2012-08-11 61 views
1

嘿,我正在使用python脚本来测试web商务网站上的功能。我把这个剧本上pythonanywhere现场,有时就像7天连续没有问题,但有天,像这样的,当我得到这个错误:Python脚本奇怪的问题

Logged in with test_cart 
    Open http://[***]/electronics/page/1 
Search ... iphone 
[****************] 
    File "/home/.../cart-pickup.py", line 58, in alo 
    site = opener.open(url) 
    File "/usr/local/lib/python2.7/urllib2.py", line 400, in open 
    response = self._open(req, data) 
    File "/usr/local/lib/python2.7/urllib2.py", line 418, in _open 
    '_open', req) 
    File "/usr/local/lib/python2.7/urllib2.py", line 378, in _call_chain 
    result = func(*args) 
    File "/usr/local/lib/python2.7/urllib2.py", line 1207, in http_open 
    return self.do_open(httplib.HTTPConnection, req) 
    File "/usr/local/lib/python2.7/urllib2.py", line 1180, in do_open 
    r = h.getresponse(buffering=True) 
    File "/usr/local/lib/python2.7/httplib.py", line 1030, in getresponse 
    response.begin() 
    File "/usr/local/lib/python2.7/httplib.py", line 407, in begin 
    version, status, reason = self._read_status() 
    File "/usr/local/lib/python2.7/httplib.py", line 371, in _read_status 
    raise BadStatusLine(line) 
    httplib.BadStatusLine: '' 
    >>>   

任何想法可能是什么? 在此先感谢

+3

我不认为这是你的Python脚本一个问题,而是一个与问题它试图与之交谈的Web服务器。 – 2012-08-11 10:41:13

回答

3

你可以教你的程序如何从这种情况下恢复,而不使用try..except崩溃:

try: 
    site = opener.open(url) # line 58 in cart-pickup.py 
except IOError: 
    print "Error: Site not loading or it isnt UP. Retrying..." 
    # return site # This will cause a NameError if site is not defined. 
    return url # Perhaps you meant this? 
except httplib.BadStatusLine: 
    # log opening `url` did not succeed, or 
    # queue it to be tried again, etc. 
    pass 
+0

我在python中有点新。所以我不知道是否有可能在一段时间内有2个除外。我的代码看起来是这样的:def ALO(URL): testurl = 1 而testurl == 1: 尝试: 网站= opener.open(URL) lagsafe = 0 除了IO错误: 打印“错误:网站无法正在加载或它不是正在重试...“ 返回站点 那么,我怎么可以你的代码? – 2012-08-11 11:15:20

+1

只需添加第二个,除了您目前的除外。 – 2012-08-11 11:20:18

+0

不起作用。它说不好的语法,并把它IDLE blinker(我使用Windows)在第二个除外:) – 2012-08-15 19:45:07