我一直在努力解决这个问题,所以我希望有人能提供帮助。
似乎是使用服务帐户访问 Google API 端点的相对简单的代码 - 但我收到 Http Error 500
它适用于 Tasks API,相同的身份验证。
我的源代码:
import httplib2
import pprint
import sys
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
f = file('key.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
'403695561042-6ntna04usrl5sscg3ovij6t4d8vfvsqp@developer.gserviceaccount.com',
key,
scope='https://www.googleapis.com/auth/apps.order.readonly')
http = httplib2.Http()
http = credentials.authorize(http)
service = build("reseller", "v1", http=http)
lists = service.subscriptions().list().execute(http=http)
print lists
回复:
HttpError: <unprintable HttpError object>
追溯:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Python/2.7/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/admin/Sites/newmind/reseller-api/app.py", line 79, in index
lists = service.subscriptions().list().execute(http=http)
File "build/bdist.macosx-10.8-intel/egg/oauth2client/util.py", line 120, in positional_wrapper
return wrapped(*args, **kwargs)
File "build/bdist.macosx-10.8-intel/egg/apiclient/http.py", line 678, in execute
raise HttpError(resp, content, uri=self.uri)
直接从 Google Sample 复制代码,只是更改了服务名称和身份验证。 http://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py 任务 API 返回具有相同凭据的 http 200。
当我使用一个非常标准的 httplib2 请求时,这是我得到的响应:
WARNING:oauth2client.util:new_request() takes at most 1 positional argument (2 given)
{'status': '500', 'content-length': '52', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'expires': 'Sat, 20 Oct 2012 06:25:19 GMT', 'server': 'GSE', '-content-encoding': 'gzip', 'cache-control': 'private, max-age=0', 'date': 'Sat, 20 Oct 2012 06:25:19 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'application/json; charset=UTF-8'}
{
"error": {
"code": 500,
"message": null
}
}
如果有人可以提供帮助,我将不胜感激。
谢谢