【问题标题】:google-api-python-client sample code gives 'module object has no attribute socket'google-api-python-client 示例代码给出“模块对象没有属性套接字”
【发布时间】:2011-11-25 19:05:34
【问题描述】:

当尝试从 google-api-python-client 中的 Latitude example 激活示例代码时,我收到以下错误:“_webapp25.py:464] 'module' object has no attribute '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)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
  handler.get(*groups)
File "H:\cproj\workspace\latitudeReminder\src\lati.py", line 31, in get
  credentials = run(FLOW, storage)
File "H:\cproj\workspace\latitudeReminder\src\apiclient\ext\authtools.py", line 116, in run
  ClientRedirectHandler)
File "C:\Python27\lib\SocketServer.py", line 405, in __init__
  self.socket = socket.socket(self.address_family,
AttributeError: 'module' object has no attribute 'socket'

我做错了什么?

【问题讨论】:

    标签: python google-api google-api-client google-api-python-client


    【解决方案1】:

    发布回溯会很有用 - 这总是有用的信息。

    我猜您的问题是您发布的示例是针对命令行应用程序的,但您正尝试将其用于 Web 服务器身份验证流程。请尝试从 oauth2client.tools 导入 run。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 2019-01-28
      • 2013-12-14
      相关资源
      最近更新 更多