我在wing101和python 3.3.2
中写了以下内容def open_page(url):
"""Open the URL string given and return its contents as file."""
page = None
increment_num_calls()
cont = False
while not cont:
try:
page = urllib2.urlopen(url)
cont = True
except urllib2.URLError as e:
print "Warning: Url load error " + str(e) + " for url " + url
#if not hasattr(e, "code"):
# raise
if hasattr(e, "code") and e.code == 401:
return None
time.sleep(TIME_DELAY_PAGE_RETRY)
return None
except httplib.BadStatusLine:
return None
return page
任何人都可以帮我弄清楚错误所说的错误
print "Warning: Url load error " + str(e) + " for url " + url
如果你想看到更多的节目让我知道,我可以发布。
答案 0 :(得分:1)
打印在Python 3中的工作方式不同
尝试更改
print "Warning: Url load error " + str(e) + " for url " + url
到
print('Warning: Url load error {} for url {}'.format(e, url))