我刚刚开始学习Gspread,并尝试访问我的Google驱动器中的电子表格之一。我按照说明进行操作,然后转到Google API控制台并创建了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