在google-api-python-client中尝试激活Latitude示例中的示例代码时,我得到以下错误:"_webapp25.py:464] 'module'对象没有属性'socket'"。代码是:
from apiclient.ext.file import Storage
from apiclient.discovery import build
from apiclient.ext.authtools import run
from oauth2client.client import OAuth2WebServerFlow
FLOW = OAuth2WebServerFlow(
client_id='SOME_CLIENT_ID',
client_secret='SOME_CLIENT_SECRET',
scope='https://www.googleapis.com/auth/latitude.current.best',
user_agent='lati-go/1.0')
storage = Storage('moderator.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = run(FLOW, storage)
http = httplib2.Http(cache=".cache")
http = credentials.authorize(http)
service = build("latitude", "v1", http = http)
data = service.currentLocation().get()
给出错误的代码是credentials = run(FLOW, storage)。回溯是:
Traceback (most recent call last):
File "C:Program Files (x86)Googlegoogle_appenginegoogleappengineextwebapp_webapp25.py", line 701, in __call__
handler.get(*groups)
File "H:cprojworkspacelatitudeRemindersrclati.py", line 31, in get
credentials = run(FLOW, storage)
File "H:cprojworkspacelatitudeRemindersrcapiclientextauthtools.py", line 116, in run
ClientRedirectHandler)
File "C:Python27libSocketServer.py", line 405, in __init__
self.socket = socket.socket(self.address_family,
AttributeError: 'module' object has no attribute 'socket'
我做错了什么?
发布回溯会很有用——这总是有用的信息。
我猜你的问题是,你发布的例子是一个命令行应用程序,但你试图使用它的web服务器身份验证流。尝试从oauth2client.tools
导入run