unboundlocalerror:local variable' res'在转让之前引用

时间:2017-09-05 14:31:49

标签: python-3.x

headers = {'Authorization': 'OAuth '+access_token}
req = urllib.request.Request('https://www.googleapis.com/oauth2/v1/userinfo',None, headers)
try:
    res = urlopen(req)
except URLError as e:
    if e.code == 401:
        # Unauthorized - bad token
        session.pop('access_token', None)
        return redirect(url_for('login'))
    return res.read()

return res.read()

UnboundLocalError:局部变量' res'在分配前引用

我该如何解决?

0 个答案:

没有答案