carolinux / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
0 stars 1 forks source link

AccountFeedQuery doesn't work with Python 2.7! #623

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

>>> import gdata
>>> import gdata.gauth
>>> tok_blob = u'token blob removed'
>>> access_token = gdata.gauth.token_from_blob(tok_blob)
>>> import gdata.analytics.client
>>> client = gdata.analytics.client.AnalyticsClient(source='My_company')
>>> client.auth_token = access_token
>>> accountFeedData = 
client.GetAccountFeed(gdata.analytics.client.AccountFeedQuery())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/cesar/virtualenvs/p27test/lib/python2.7/site-packages/gdata/analytics/client.py", line 61, in get_account_feed
    **kwargs)
  File "/Users/cesar/virtualenvs/p27test/lib/python2.7/site-packages/gdata/client.py", line 635, in get_feed
    **kwargs)
  File "/Users/cesar/virtualenvs/p27test/lib/python2.7/site-packages/gdata/client.py", line 265, in request
    uri=uri, auth_token=auth_token, http_request=http_request, **kwargs)
  File "/Users/cesar/virtualenvs/p27test/lib/python2.7/site-packages/atom/client.py", line 110, in request
    self.auth_token.modify_request(http_request)
  File "/Users/cesar/virtualenvs/p27test/lib/python2.7/site-packages/gdata/gauth.py", line 980, in modify_request
    token_secret=self.token_secret, verifier=self.verifier)
  File "/Users/cesar/virtualenvs/p27test/lib/python2.7/site-packages/gdata/gauth.py", line 614, in generate_hmac_signature
    hashed = hmac.new(hash_key, base_string, hashlib.sha1)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 133, in new
    return HMAC(key, msg, digestmod)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 72, in __init__
    self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode

What is the expected output? What do you see instead?

I expect accountFeedData to have an accountFeed object

What version of the product are you using?
2.0.14 but also tested with 2.0.17 and the same problem occurs.

Please provide any additional information below.

The code above works perfectly with Python 2.6:

>>> ...
>>> accountFeedData = 
client.GetAccountFeed(gdata.analytics.client.AccountFeedQuery())
>>> accountFeedData
<gdata.analytics.data.AccountFeed object at 0x10e3210>

Original issue reported on code.google.com by ce...@leftronic.com on 24 Jun 2012 at 10:12

GoogleCodeExporter commented 9 years ago
Figured out what's causing the problem, at least:

This line in gauth.py:

hash_key = '%s&%s' % (urllib.quote(consumer_secret, safe='~'),
                          urllib.quote(token_secret, safe='~'))

Returns a unicode string for Python 2.7 and a regular string for 2.6. hmac.new 
does not seem to like unicode inputs - only bytes. Can we have a patch for 
this? How is it possible no one else has this problem - does no one use Python 
2.7?

Original comment by ce...@leftronic.com on 24 Jun 2012 at 11:57

GoogleCodeExporter commented 9 years ago
I am seeing the same problem as well. 2.6.5 does not error, but 2.7.3 does. 

Original comment by camemb...@gmail.com on 14 Sep 2012 at 9:31

GoogleCodeExporter commented 9 years ago
Same happens to me. The workaround that solve this was encode tokens and 
secrets to ascii.
Example:
gauth.OAuthHmacToken(
            settings.GDATA_CREDS['key'].encode('ascii'),
            settings.GDATA_CREDS['secret'].encode('ascii'),
            token.token.encode('ascii'),
            token.token_secret.encode('ascii'),
            gauth.ACCESS_TOKEN
        )

Original comment by miguel.m...@gmail.com on 19 Jun 2013 at 12:54