issue with authorizing credentials
See original GitHub issueI am running the basic authentication process (after generating the OAuth credentials outlined in the documentation: https://gspread.readthedocs.io/en/latest/oauth2.html
Here is my code for reference:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('my_creds-06044a753234.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("My Sheet").sheet1
I am receiving a type error, saying the argument for the authorize function in my code is a string. Has anyone seen this issue? I was not able to find any other issues where this was replicated. I am using python 3.7 and am running this code on python anywhere: https://www.pythonanywhere.com/ Any ideas would be greatly appreciated.
Full Error:
Traceback (most recent call last):
File "/home/data/DTR_GoogleSheets/test.py", line 9, in <module>
gc = gspread.authorize(credentials)
File "/home/data/.local/lib/python3.7/site-packages/gspread/__init__.py", line 38, in authorize
client.login()
File "/home/data/.local/lib/python3.7/site-packages/gspread/client.py", line 51, in login
self.auth.refresh(http)
File "/home/data/.local/lib/python3.7/site-packages/oauth2client/client.py", line 545, in refresh
self._refresh(http)
File "/home/data/.local/lib/python3.7/site-packages/oauth2client/client.py", line 749, in _refresh
self._do_refresh_request(http)
File "/home/data/.local/lib/python3.7/site-packages/oauth2client/client.py", line 780, in _do_refresh_request
body=body, headers=headers)
File "/home/data/.local/lib/python3.7/site-packages/oauth2client/transport.py", line 282, in request
connection_type=connection_type)
File "/usr/lib/python3.7/site-packages/httplib2/__init__.py", line 1957, in request
cachekey,
File "/usr/lib/python3.7/site-packages/httplib2/__init__.py", line 1622, in _request
conn, request_uri, method, body, headers
File "/usr/lib/python3.7/site-packages/httplib2/__init__.py", line 1528, in _conn_request
conn.connect()
File "/usr/lib/python3.7/site-packages/httplib2/__init__.py", line 1309, in connect
sock.connect((self.host, self.port))
File "/usr/lib/python3.7/site-packages/socks.py", line 406, in connect
self.__negotiatehttp(destpair[0],destpair[1])
File "/usr/lib/python3.7/site-packages/socks.py", line 357, in __negotiatehttp
while resp.find("\r\n\r\n")==-1:
TypeError: argument should be integer or bytes-like object, not 'str'
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9
Top Results From Across the Web
Obtaining user authorization credentials - IBM
The authorization credentials contain user identity information that is needed to make authorization decisions, such as group memberships. The credentials also ...
Read more >Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >Troubleshoot issues with resuming an account - Search Ads ...
Solution: See the steps that follow to check the authorization status of the engine account and verify that your credentials allow Search Ads...
Read more >Authentication vs. Authorization - Auth0
Challenges the user to validate credentials (for example, through passwords, answers to security questions, or facial recognition), Verifies whether access is ...
Read more >Why am I having trouble signing in to Microsoft Teams?
You're not using the right credentials. The Windows credentials you signed in with are different than your Microsoft 365 credentials. Try to sign...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey all, I was having similar OAuth issues when trying to update some old code (using gspread==0.6.2) to use the latest versions (gspread>=3.0.0) and I believe it might be the same solution required here. The scopes OP is using were the same as mine,
https://spreadsheets.google.com/feeds
, which worked for old versions of the Google Sheets API. But now we should be using v4 of the Google Sheets API with the correct scopehttps://www.googleapis.com/auth/spreadsheets
.As per the Google Sheets API docs: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get#authorization-scopes
Hope that helps someone else too.
TL;DR: Change
https://spreadsheets.google.com/feeds
tohttps://www.googleapis.com/auth/spreadsheets
My issue was fixed by running
pip3.7 install --user --force-reinstall PySocks
in a Bash console on the platform.