import json import gspread from oauth2client.client import SignedJwtAssertionCredentials json_key = json.load(open('Crowds-9569176f5988.json')) scope = ['https://spreadsheets.google.com/feeds'] credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
Error:
Traceback (most recent call last): File "C:\Users\sony\Desktop\Python\new.py", line 8, in <module> credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope) File "C:\Python34\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper return wrapped(*args, **kwargs) File "C:\Python34\lib\site-packages\oauth2client\client.py", line 1469, in __init__ self.private_key = base64.b64encode(private_key) File "C:\Python34\lib\base64.py", line 62, in b64encode encoded = binascii.b2a_base64(s)[:-1] TypeError: 'str' does not support the buffer interface
I tried to encode a string using .encode() , but gspread.authorize() does not support this type. This is [documentation] [1], which, apparently, does not help much. I am using Python 3.4. I think the documentation code only works for versions up to 3.
EDIT:
credentials = SignedJwtAssertionCredentials.from_json(json_key['client_email'], json_key['private_key'], scope)
Traceback (last last call): File "C: \ Users \ sony \ Desktop \ Python \ new.py", line 9, in credentials = SignedJwtAssertionCredentials.from_json (json_key ['client_email'], json_key ['private_key'], scope ) TypeError: from_json () takes 2 positional arguments, but 4 are given [Finished in 1.0 with exit code 1]
[1]: http://gspread.readthedocs.org/en/latest/oauth2.html
credentials = SignedJwtAssertionCredentials.from_json(json_key)
Traceback (last last call): File "C: \ Users \ sony \ Desktop \ Python \ new.py", line 8, in credentials = SignedJwtAssertionCredentials.from_json (json_key) File "C: \ Python34 \ lib \ site-packages \ oauth2client \ client.py ", line 1479, in from_json data = json.loads (s) File" C: \ Python34 \ lib \ json__init __. py ", line 312, in s class loads. name )) TypeError: the JSON object must be str, not 'dict'