2016-12-04 127 views
5

我试图根据Google的Gmail API使用oauth2来使用quickstart.py(https://developers.google.com/gmail/api/quickstart/python)。我收到下面的错误。Google API Python - KeyError:_module

Traceback (most recent call last): 
    File "quickstart.py", line 68, in <module> 
    main() 
    File "quickstart.py", line 54, in main 
    credentials = get_credentials() 
    File "quickstart.py", line 37, in get_credentials 
    credentials = store.get() 
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 407, in get 
     return self.locked_get() 
     File "/usr/local/lib/python2.7/dist-packages/oauth2client/file.py", line 54, in locked_get 
     credentials = client.Credentials.new_from_json(content) 
     File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 302, in new_from_json 
     module_name = data['_module'] 
    KeyError: '_module' 

回答

5

最后,我想通了。从Google API控制台下载的client_secret.json文件应放在与python quickstart.py文件相同的目录中,而不要放在~/.credentials目录中。这解决了这个问题。