google-api-python-client 示例代码给出“模块对象没有属性套接字”

发布于 2024-12-18 05:21:58 字数 1609 浏览 1 评论 0原文

尝试从 Google-api-python-client 中的纬度示例 我收到以下错误:“_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)\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'

我做错了什么?

When trying to activate sample code from the Latitude example in google-api-python-client I get the following error: "_webapp25.py:464] 'module' object has no attribute 'socket'".
The code is:

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()

The code that gives the error is credentials = run(FLOW, storage).
The traceback is:

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'

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-12-25 05:21:58

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

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

It would have been useful to post the traceback - that's always helpful information.

I would guess that your problem is that the example you post is for a command-line application, yet you're trying to use it for a web server authentication flow. Try importing run from oauth2client.tools instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文