Gspread无法连接google api

2024-09-26 22:12:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始学习Gspread,并尝试访问我的google驱动器中的一个电子表格。我按照说明去googleapi控制台创建了一个JSON文件。但总是无法连接google api

 import gspread
 from oauth2client.service_account import ServiceAccountCredentials

     def one_spreadsheet():
     scope = ['https://spreadsheets.google.com/feeds']
     credentials = ServiceAccountCredentials.from_json_keyfile_name('Quickstart-0302d8.json', scope)
     conn = gspread.authorize(credentials)


Traceback (most recent call last):
File "D:/My Projects/python-gspread-sheets-master/gsheet.py", line 31, in <module>
populate_spreadsheet()
File "D:/My Projects/python-gspread-sheets-master/gsheet.py", line 9, in one_spreadsheet
conn = gspread.authorize(credentials)
File "C:\Users\yijji\AppData\Roaming\Python\Python37\site-packages\gspread\__init__.py", line 38, in authorize
client.login()
File "C:\Users\yijji\AppData\Roaming\Python\Python37\site-packages\gspread\client.py", line 51, in login
self.auth.refresh(http)
File "C:\Users\yijji\AppData\Roaming\Python\Python37\site-packages\oauth2client\client.py", line 545, in refresh
self._refresh(http)
File "C:\Users\yijji\AppData\Roaming\Python\Python37\site-packages\oauth2client\client.py", line 749, in _refresh
self._do_refresh_request(http)
File "C:\Users\yijji\AppData\Roaming\Python\Python37\site-packages\oauth2client\client.py", line 780, in _do_refresh_request
body=body, headers=headers)
File "C:\Users\yijji\AppData\Roaming\Python\Python37\site-packages\oauth2client\transport.py", line 282, in request
connection_type=connection_type)
File "D:\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1926, in request
cachekey,
File "D:\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1595, in _request
conn, request_uri, method, body, headers
File "D:\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1501, in _conn_request
conn.connect()
File "D:\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1356, in connect
raise socket_err
File "D:\Python\Python37\lib\site-packages\httplib2\__init__.py", line 1289, in connect
sock.connect((self.host, self.port))
TimeoutError: [WinError 10060]A connection attempt failed because the connected party did not properly respond after a period of time

Tags: inpyinitrequestpackageslinesiteroaming

热门问题