python导入email_extractor语法错误除外

时间:2017-03-20 08:55:37

标签: python import syntax except

我正在尝试导入email_extractor,但在除urllib2.URLError之外的第一个除语句中出现错误,详情:

编辑该行时的PyCharm消息说:

"Python 3.6 does not support this syntax"

我该如何解决这个问题?

def getPage(url):
    try:
        f = urllib2.urlopen(url)
        page = ""
        for i in f.readlines():
            page += i
        date = f.info().getdate('Last-Modified')
        if date == None:
            date = (0, 0, 0)
        else:
            date = date[:3]
        f.close()
        return (page, date, f.url)
    except urllib2.URLError, detail:
        pass
        return (None, (0,0,0), "")

1 个答案:

答案 0 :(得分:0)

except块只是一个错误的语法,它应该带有括号:

except (urllib2.URLError, detail):
    pass
    return (None, (0,0,0), "")