Python SSL错误 解密失败或坏的记录mac

12
我正在尝试使用gspread Python模块读取Google电子表格。但是我从ssl中得到了一些错误。我已经尝试查看此问题,但无法使其正常工作。gspread模块在内部使用python request,似乎使用Python的ssl包。下面提供了代码(我编写的)和堆栈跟踪以及环境详细信息。 环境:
  • Python:2.7.13
  • Ubuntu:14.04
  • openssl:1.0.1f 6 Jan 2014
代码:
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

堆栈跟踪:

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)

任何帮助都将不胜感激。
更新: 我已经从头开始设置了新机器上的所有内容,并且还更新了oauth客户端以利用新的API版本。无法使上述环境工作,因此暂时保留此问题。

你使用的oauth2client版本是多少? - Jacques Gaudin
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Jacques Gaudin
3
看起来这是人们在使用多个连接时遇到的问题。你尝试过使用 keep-alive 吗?from gspread.httpsession import HTTPSession``http_session = HTTPSession(headers={'Connection':'Keep-Alive'})``gc = gspread.Client(credentials, http_session)``gc.login() - Jacques Gaudin
@JacquesGaudin 谢谢您指出这个问题。我会尝试并更新给您。 - Nikhil N
你成功了吗? - Jacques Gaudin
显示剩余3条评论
3个回答

5

我当时连接了Wifi,遇到了这个问题。之后我用以太网电缆将电脑连接上,问题就得到了解决。


对我来说,我必须做相反的事情...我插上了电源,然后就拔掉了...谢谢吧,我猜... - ravi
1
我从5GHz的wifi切换到了老的wifi,现在它能用了。 - Remy Mellet

2

我通过使用pip更新urllib3库来解决了这个问题。

pip install urllib3 --upgrade

-1
根据其他答案,我只是简单地关闭并重新打开了我的WiFi,这对我起了作用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接