python - 我在 python 中使用 gspread 模块时遇到了麻烦
问题描述
我打算访问谷歌电子表格以使用 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] 现有连接被远程主机强行关闭
请给我任何解决方案。感谢您的考虑。
解决方案
推荐阅读
- html - 如何以角度在行的下一列中打开routerLink?
- c# - 在 asp.net webform 中比较和删除列表框中的项目
- java - 我可以让这个电话验证器正则表达式更高效吗?
- python - 将字符串列表转换为非字符串列表
- spring - Spring - 如何在 postForObject 方法中使用超类作为 responseType?
- android-studio - Android 布局编辑器错误(无法在编辑器上创建约束):java.lang.IllegalArgumentException:集合为空
- coldfusion - 当我们在 ColdFusion 中使用 API 调用(POST 请求)将参数数量传递给服务器时,如何解决“POST 请求超出”错误?
- mysql - 按最常见类型的顺序获取电影,然后是关键字
- vue.js - 在 bootstrap-vue 中自定义 b 分页
- android - 运行代码时显示进度对话框的问题