-5

我用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

如果你想看更多的节目让我知道,我可以发布它。

4

1 回答 1

1

打印在 Python 3 中的工作方式不同

尝试改变

print "Warning: Url load error " + str(e) + " for url " + url

print('Warning: Url load error {} for url {}'.format(e, url))
于 2013-07-25T13:19:48.557 回答