问题
I am trying to use gspread python module to read the google spreadsheet. But I am getting some error from ssl. I have tried to look into this, but couldn't able to make it work. The gspread module is using python request internally which seems to be use python's ssl package. The code (I have written) and stack trace is provided below with env details.
Env:
- python: 2.7.13
- Ubuntu: 14.04
- openssl: 1.0.1f 6 Jan 2014
Code:
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(user_email, private_key, scope)
google_client = gspread.authorize(credentials)
worksheet = google_client.open_by_url(<worksheet_url>).get_worksheet(1)
list_of_rows = worksheet.get_all_values()
print list_of_rows
Stack trace:
File "<console>", line 1, in <module>
File "/home/nikhil/.venv/nikhil/src/gspread/gspread/models.py", line 344, in get_all_values
cells = self._fetch_cells()
File "/home/nikhil/.venv/nikhil/src/gspread/gspread/models.py", line 231, in _fetch_cells
feed = self.client.get_cells_feed(self)
File "/home/nikhil/.venv/nikhil/src/gspread/gspread/client.py", line 186, in get_cells_feed
r = self.session.get(url)
File "/home/nikhil/.venv/nikhil/src/gspread/gspread/httpsession.py", line 76, in get
return self.request('GET', url, **kwargs)
File "/home/nikhil/.venv/nikhil/src/gspread/gspread/httpsession.py", line 68, in request
response = func(url, data=data, headers=request_headers, verify=False)
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/sessions.py", line 469, in get
return self.request('GET', url, **kwargs)
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/sessions.py", line 606, in send
r.content
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/models.py", line 724, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/models.py", line 653, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 256, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/home/nikhil/.venv/nikhil/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 186, in read
data = self._fp.read(amt)
File "/usr/local/lib/python2.7.13/lib/python2.7/httplib.py", line 573, in read
return self._read_chunked(amt)
File "/usr/local/lib/python2.7.13/lib/python2.7/httplib.py", line 642, in _read_chunked
value.append(self._safe_read(chunk_left))
File "/usr/local/lib/python2.7.13/lib/python2.7/httplib.py", line 688, in _safe_read
chunk = self.fp.read(min(amt, MAXAMOUNT))
File "/usr/local/lib/python2.7.13/lib/python2.7/socket.py", line 384, in read
data = self._sock.recv(left)
File "/usr/local/lib/python2.7.13/lib/python2.7/ssl.py", line 766, in recv
return self.read(buflen)
File "/usr/local/lib/python2.7.13/lib/python2.7/ssl.py", line 653, in read
v = self._sslobj.read(len)
SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1864)
Any help would be much appreciated.
UPDATE: I have setup everything from scratch on new machine and also updated the oauth client to utilize new API version. Couldn't make the above env work so keeping this question open for now.
回答1:
I was on Wifi and it happened to me. I plugged the computer with an ethernet cable and it solved the problem for me.
来源:https://stackoverflow.com/questions/41780517/python-ssl-error-decryption-failed-or-bad-record-mac