python 中的 gdata 分析客户端问题
我能够使用 Google 的 gdata python 库成功检索 Google Analytics 的 OAuth 访问令牌。
但是,我尝试使用令牌访问 Google Analytics 数据失败。这是相关的代码片段:
client = gdata.analytics.client.AnalyticsClient(source='myapp')
client.auth_token = access_token # retrieved earlier
dataQuery = gdata.analytics.client.DataFeedQuery({
'ids': 'ga:********',
'start-date': '2011-03-23',
'end-date': '2011-04-04',
'metrics': 'ga:percentNewVisits',
'max-results': 50})
data = client.GetDataFeed(dataQuery)
我得到以下堆栈跟踪:
回溯(最近一次调用最后一次):
文件 “/Library/Python/2.6/site-packages/django/core/servers/basehttp.py”, 第 280 行,运行中 self.结果 = 应用程序(self.environ, self.start_response)文件 “/Library/Python/2.6/site-packages/django/core/servers/basehttp.py”, 第 674 行,在通话中 返回 self.application(environ, start_response)
文件 “/Library/Python/2.6/site-packages/django/core/handlers/wsgi.py”, 第 248 行,在通话中 响应 = self.get_response(请求)
文件 “/Library/Python/2.6/site-packages/django/core/handlers/base.py”, 第 141 行,在 get_response 中 返回 self.handle_uncaught_exception(请求, 解析器,sys.exc_info())
文件 “/Library/Python/2.6/site-packages/django/core/handlers/base.py”, 第 100 行,在 get_response 中 响应 = 回调(请求,*callback_args,**callback_kwargs)
文件 “/Library/Python/2.6/site-packages/django/contrib/auth/decorators.py”, 第 25 行,在 _wrapped_view 中 返回 view_func(请求, *args, **kwargs)
文件 "/Users/***/***< /strong>/**/***/**/googleAnalyticsOauth.py", 第 122 行,在 googleAnalyticsTest 中 数据 = client.GetDataFeed(dataQuery)
文件 “build/bdist.macosx-10.6-universal/egg/gdata/analytics/client.py”, 第 77 行,在 get_data_feed 中 **夸格斯)
文件 “build/bdist.macosx-10.6-universal/egg/gdata/client.py”, 第 635 行,在 get_feed 中 **夸格斯)
文件 “build/bdist.macosx-10.6-universal/egg/gdata/client.py”, 第 265 行,根据要求 uri=uri,auth_token=auth_token,http_request=http_request,**kwargs)
文件 “build/bdist.macosx-10.6-universal/egg/atom/client.py”, 110 号线,应要求 self.auth_token.modify_request(http_request)
文件 “build/bdist.macosx-10.6-universal/egg/gdata/gauth.py”, 980行,在modify_request中 token_secret=self.token_secret, verifier=self.verifier)
文件 “build/bdist.macosx-10.6-universal/egg/gdata/gauth.py”, generate_hmac_signature 中的第 604 行 接下来,令牌,验证者=验证者)
文件 “build/bdist.macosx-10.6-universal/egg/gdata/gauth.py”, 第 565 行,在 build_oauth_base_string 中 urllib.quote(params[key], safe='~')))
文件 “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py”, 第 1216 行,引用 res = map(safe_map.getitem, s)
类型错误:map() 的参数 2 必须 支持迭代
任何人都知道可能出现什么问题吗?
谢谢!
I was able to successfully retrieve an OAuth access token for Google Analytics using Google's gdata python library.
However, my attempt to use the token to access Google Analytics data is failing. Here is the relevant code snippet:
client = gdata.analytics.client.AnalyticsClient(source='myapp')
client.auth_token = access_token # retrieved earlier
dataQuery = gdata.analytics.client.DataFeedQuery({
'ids': 'ga:********',
'start-date': '2011-03-23',
'end-date': '2011-04-04',
'metrics': 'ga:percentNewVisits',
'max-results': 50})
data = client.GetDataFeed(dataQuery)
I get the following stacktrace:
Traceback (most recent call last):
File
"/Library/Python/2.6/site-packages/django/core/servers/basehttp.py",
line 280, in run
self.result = application(self.environ,
self.start_response)File
"/Library/Python/2.6/site-packages/django/core/servers/basehttp.py",
line 674, in call
return self.application(environ, start_response)File
"/Library/Python/2.6/site-packages/django/core/handlers/wsgi.py",
line 248, in call
response = self.get_response(request)File
"/Library/Python/2.6/site-packages/django/core/handlers/base.py",
line 141, in get_response
return self.handle_uncaught_exception(request,
resolver, sys.exc_info())File
"/Library/Python/2.6/site-packages/django/core/handlers/base.py",
line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)File
"/Library/Python/2.6/site-packages/django/contrib/auth/decorators.py",
line 25, in _wrapped_view
return view_func(request, *args, **kwargs)File
"/Users/***/***/**/***/**/googleAnalyticsOauth.py",
line 122, in googleAnalyticsTest
data = client.GetDataFeed(dataQuery)File
"build/bdist.macosx-10.6-universal/egg/gdata/analytics/client.py",
line 77, in get_data_feed
**kwargs)File
"build/bdist.macosx-10.6-universal/egg/gdata/client.py",
line 635, in get_feed
**kwargs)File
"build/bdist.macosx-10.6-universal/egg/gdata/client.py",
line 265, in request
uri=uri, auth_token=auth_token, http_request=http_request, **kwargs)File
"build/bdist.macosx-10.6-universal/egg/atom/client.py",
line 110, in request
self.auth_token.modify_request(http_request)File
"build/bdist.macosx-10.6-universal/egg/gdata/gauth.py",
line 980, in modify_request
token_secret=self.token_secret, verifier=self.verifier)File
"build/bdist.macosx-10.6-universal/egg/gdata/gauth.py",
line 604, in generate_hmac_signature
next, token, verifier=verifier)File
"build/bdist.macosx-10.6-universal/egg/gdata/gauth.py",
line 565, in build_oauth_base_string
urllib.quote(params[key], safe='~')))File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py",
line 1216, in quote
res = map(safe_map.getitem, s)TypeError: argument 2 to map() must
support iteration
Anyone have any ideas what could be going wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题出在 2.0.15 版本中的 gauth.py(gdata 客户端库的一部分)中的第 587 行左右。
传递给 urllib.quote 的“max-results”参数的值为 10000,一个整数,而不是字符串,因此它没有迭代器。
我的快速 hacky 修复是:
您可以使用 pdb 自己追踪问题,如下所示:
如果一切正常(就像将上面的 hack 添加到 gauth.py 时),您将看到以下内容而不是堆栈跟踪:
The problem is in gauth.py (part of the gdata client library) at about line 587 in version 2.0.15.
The value for the "max-results" parameter being passed to urllib.quote is 10000, an integer, not a string, so it doesn't have an iterator.
My quick hacky fix is:
You can track down the problem yourself by using pdb, like this:
If everything works (like when you add my hack above to gauth.py), you'll see this instead of the stack trace:
FWIW,必须执行以下操作:
my_client.auth_token = gdata.gauth.OAuthHmacToken(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET, gdata.gauth.ACCESS_TOKEN)
通过
FWIW, one has to do the following:
my_client.auth_token = gdata.gauth.OAuthHmacToken(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET, gdata.gauth.ACCESS_TOKEN)
Via