我有一个问题,因为我对Python了解不多,我希望别人能帮助我了解我的问题所在。
我正在建立一个便携式无线收音机。Raspberry Pi利用Pianobar转到Pandora服务器,登录到我的帐户,获取我的站点,然后开始播放第一个站点。
我正在遵循Adafruit的官方指南:https://learn.adafruit.com/pi-wifi-radio/overview
我一直跟随着向导直到Pianobar开始工作。我可以从命令行运行"pianobar“。它在不到10秒的时间内连接并开始播放音乐。
但是,当我启动允许16x2 LCD键盘与pianobar接口的脚本时,它不起作用。
更具体地说,它通过了脚本的前半部分。液晶屏显示IP地址,并显示“正在检索站点列表...”。10秒后,脚本退出,并显示所有这些内容。
pi@pandora ~/Python-WiFi-Radio $ sudo python PiPhi.py
Spawning pianobar...
Receiving station list...
Traceback (most recent call last):
File "PiPhi.py", line 288, in <module>
stationList, stationIDs = getStations()
File "PiPhi.py", line 190, in getStations
pianobar.expect('Select station: ', timeout=10)
File "/usr/local/lib/python2.7/dist-packages/pexpect.py", line 1311, in expect
return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
File "/usr/local/lib/python2.7/dist-packages/pexpect.py", line 1325, in expect_list
return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
File "/usr/local/lib/python2.7/dist-packages/pexpect.py", line 1409, in expect_loop
raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
<pexpect.spawn object at 0xb6b305b0>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/sudo
args: ['/usr/bin/sudo', '-u', 'pi', 'pianobar']
searcher: searcher_re:
0: re.compile("Select station: ")
TIME: -03:35/03:43
TIME: -03:35/03:43
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 2315
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
pi@pandora ~/Python-WiFi-Radio $ http://pastebin.com/6Lm3dTwx -这是我尝试运行的脚本
根据我的基本知识,它似乎花费了比任何超时更长的时间来检索电台列表。我完全迷路了,请帮帮我。谢谢!
发布于 2014-08-23 22:45:51
我也遇到了同样的问题,为了解决技术含量较低的问题,我在启动脚本中对google进行了10次pinged。这为系统提供了足够长的时间来稳定网络连接。
发布于 2014-09-09 05:57:50
我发现userid "pi“是用PiPhi.py硬编码的!更改行33 (PICKLEFILE),286 (pepect.spawn('sudo -u pi...解决了我的问题..
希望这能帮上忙..
发布于 2014-09-17 00:53:29
这里有两个潜在的问题。我在创建这个过程时遇到了困难。这在pianobar.excect中显示为“Get stations...OK.\r\n”的EOF错误。要查看发生了什么,请处理EOF异常并打印pianobar.before:
# Launch pianobar as pi user (to use same config data, etc.) in background:
print('Spawning pianobar...')
pianobar = pexpect.spawn('sudo -u pi /home/pi/pianobar/pianobar', timeout=60)
print('Receiving station list...')
expectIdx = pianobar.expect(['Get stations... Ok.\r\n', pexpect.EOF, pexpect.TIMEOUT])
if expectIdx == 0:
stationList, stationIDs = getStations()
try: # Use station name from last session
stationNum = stationList.index(defaultStation)
except: # Use first station in list
stationNum = 0
print 'Selecting station ' + stationIDs[stationNum]
pianobar.sendline(stationIDs[stationNum])
elif expectIdx == 1: # EOF
print 'pianobar.expect EOF error'
print pianobar.before # shows response from pianobar spawn
pianobar.kill(0)
elif expectIdx == 2: # TIMEOUT
print 'pianobar.expect TIMEOUT error'
pianobar.kill(0)
我通过指定pianobar的完整路径解决了这个问题(如上所示)。
第二个问题可能是因为您的pianobar配置中有一个有效的默认工作站。如果在这种情况下,启动时没有显示选择站点列表,则需要请求该列表。此错误出现在getStations()中的pianobar.expect中。我通过在初始请求超时时请求站点列表来修复此问题:
expectIdx = pianobar.expect(['Select station: ', pexpect.EOF, pexpect.TIMEOUT], timeout=10)
if expectIdx == 1: # EOF
print 'pianobar.expect EOF error at getStations'
print pianobar.before # shows response from pianobar spawn
pianobar.kill(0)
elif expectIdx == 2: # TIMEOUT
# try requesting the station list
pianobar.send('s')
pianobar.expect('Select station', timeout=10)
https://stackoverflow.com/questions/25437595
复制相似问题