我一直拉着我的頭髮試圖找出這一個,所以我希望有人可以幫助。Google服務帳戶Http錯誤500 - Python
好像相對簡單的代碼訪問與服務帳戶 - 谷歌的API點,但我得到的HTTP錯誤500
它正常工作與任務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(
'[email protected]account.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)
代碼直接從谷歌樣品複製,只是改變了服務的名稱,認證。 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
}
}
如果有人可以幫助,我會非常感激。
感謝
是的,我做了,它使用Flow令牌工作正常。但當然,它很快就會過期,所以如果沒有特權用戶在場,我無法提出請求。 –
@NickWoodhams陷阱。我從不喜歡與認證摔跤。最後的想法(你知道似乎比我更懂事,所以這可能是無關緊要的) - 使用Flow令牌時,將訪問類型設置爲離線幫助緩解過期問題?這對我來說已經有效,但我的用例可能不同(可能不那麼複雜)。 – RocketDonkey
不要低估自己,那正是我需要的。這將繞開這個問題。你知道令牌有效多久嗎? –