Python脚本奇怪的问题
嘿,我正在使用python脚本测试web商务网站上的功能。我将此脚本放在Pythonywhere站点上,有时连续工作7天没有问题,但有时会出现如下错误:Python脚本奇怪的问题,python,urllib2,httplib,Python,Urllib2,Httplib,嘿,我正在使用python脚本测试web商务网站上的功能。我将此脚本放在Pythonywhere站点上,有时连续工作7天没有问题,但有时会出现如下错误: Logged in with test_cart Open http://[***]/electronics/page/1 Search ... iphone [****************] File "/home/.../cart-pickup.py", line 58, in alo site = opener
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: ''
>>>
你知道可能是什么吗?
提前感谢您可以通过使用
try.教您的程序如何在不崩溃的情况下恢复。
除外:
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
我认为这不是Python脚本的问题,而是它试图与之对话的web服务器的问题。我是Python新手。所以我不知道是否有可能在一段时间内有两个例外。我的代码如下所示:def alo(url):testurl=1,而testurl==1:try:site=opener.open(url)lagsafe=0,除了IOError:print“错误:站点未加载或未启动。重试…”返回站点,那么我如何才能找到你的代码?只需在当前的except之后添加第二个except。不起作用。它说错误的语法,并把它闲置闪烁(我使用windows)在第二,除了:)我检查了我的代码;我没有看到任何错误。请发布您的代码。可能我在这里做错了:#日志打开
url
没有成功,或者#排队等待重试,等等。您能给我一些例子吗?谢谢