我在python中使用gspread模块遇到麻烦

时间:2019-11-01 16:33:34

标签: python python-3.x google-sheets

我正要访问Google电子表格,以使用python gspread对此进行数据写入。 我使用了以下代码:

import gspread
from oauth2client.service_account import ServiceAccountCredentials


scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

sheet = client.open('Copy of Google Merchant Center feed - Di: Produktflöde').sheet1

list_of_hashes = sheet.get_all_records()
print(list_of_hashes)

这是来自https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html的示例代码,我创建了所需的凭据和客户端机密json文件。

但是我遇到了麻烦,找不到任何解决方案。

错误在下面

Traceback (most recent call last):
  File "Bot2.py", line 16, in <module>
    client = gspread.authorize(creds)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\gspread\__init__.py", line 38, in authorize
    client.login()
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\gspread\client.py", line 51, in login
    self.auth.refresh(http)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\oauth2client\client.py", line 545, in refresh
    self._refresh(http)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\oauth2client\client.py", line 749, in _refresh
    self._do_refresh_request(http)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\oauth2client\client.py", line 780, in _do_refresh_request
    body=body, headers=headers)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\oauth2client\transport.py", line 282, in request
    connection_type=connection_type)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1957, in request
    cachekey,
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1622, in _request
    conn, request_uri, method, body, headers
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1528, in _conn_request
    conn.connect()
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1376, in connect
    raise socket_err
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1311, in connect
    self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
    session=session
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 870, in _create
    self.do_handshake()
  File "C:\Users\Dragon\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

(有时,我看到此错误TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond而不是connectionreseterror。)

我试图通过此错误声明解决此问题,但我发现的所有答案都没有帮助。

ConnectionResetError:[WinError 10054]现有连接被远程主机强行关闭

请给我任何解决方案。谢谢您的考虑。

0 个答案:

没有答案