Я встретил TimeoutError при запуске кода Python
---------------------------------------------------------------------------
TimeoutError Traceback (most recent call last)
<ipython-input-6-06414818a9b8> in <module>
6 credentials = ServiceAccountCredentials.from_json_keyfile_name('test.json', scope)
7
----> 8 gc = gspread.authorize(credentials)
9
10 wks = gc.open("reivewapi").sheet1
~/miniconda3/envs/udacity/lib/python3.6/site-packages/gspread/__init__.py in authorize(credentials, client_class)
36 """
37 client = client_class(auth=credentials)
---> 38 client.login()
39 return client
~/miniconda3/envs/udacity/lib/python3.6/site-packages/gspread/client.py in login(self)
49
50 http = httplib2.Http()
---> 51 self.auth.refresh(http)
52
53 self.session.headers.update({
~/miniconda3/envs/udacity/lib/python3.6/site-packages/oauth2client/client.py in refresh(self, http)
543 request.
544 """
--> 545 self._refresh(http)
546
547 def revoke(self, http):
~/miniconda3/envs/udacity/lib/python3.6/site-packages/oauth2client/client.py in _refresh(self, http)
747 """
748 if not self.store:
--> 749 self._do_refresh_request(http)
750 else:
751 self.store.acquire_lock()
~/miniconda3/envs/udacity/lib/python3.6/site-packages/oauth2client/client.py in _do_refresh_request(self, http)
778 resp, content = transport.request(
779 http, self.token_uri, method='POST',
--> 780 body=body, headers=headers)
781 content = _helpers._from_bytes(content)
782 if resp.status == http_client.OK:
~/miniconda3/envs/udacity/lib/python3.6/site-packages/oauth2client/transport.py in request(http, uri, method, body, headers, redirections, connection_type)
280 return http_callable(uri, method=method, body=body, headers=headers,
281 redirections=redirections,
--> 282 connection_type=connection_type)
283
284
~/miniconda3/envs/udacity/lib/python3.6/site-packages/httplib2/__init__.py in request(self, uri, method, body, headers, redirections, connection_type)
1924 headers,
1925 redirections,
-> 1926 cachekey,
1927 )
1928 except Exception as e:
~/miniconda3/envs/udacity/lib/python3.6/site-packages/httplib2/__init__.py in _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)
1593
1594 (response, content) = self._conn_request(
-> 1595 conn, request_uri, method, body, headers
1596 )
1597
~/miniconda3/envs/udacity/lib/python3.6/site-packages/httplib2/__init__.py in _conn_request(self, conn, request_uri, method, body, headers)
1499 try:
1500 if conn.sock is None:
-> 1501 conn.connect()
1502 conn.request(method, request_uri, body, headers)
1503 except socket.timeout:
~/miniconda3/envs/udacity/lib/python3.6/site-packages/httplib2/__init__.py in connect(self)
1354 break
1355 if not self.sock:
-> 1356 raise socket_err
1357
1358
~/miniconda3/envs/udacity/lib/python3.6/site-packages/httplib2/__init__.py in connect(self)
1287 if has_timeout(self.timeout):
1288 sock.settimeout(self.timeout)
-> 1289 sock.connect((self.host, self.port))
1290
1291 self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
TimeoutError: [Errno 60] Operation timed out
Я создал учетные данные, скачал их и поделился ими с моей электронной таблицей. Я также включил API Google Drive API и API электронных таблиц Google. Я действительно хочу знать, что я могу сделать сейчас.
Вот мой код,
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('test.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("reivewapi").sheet1
reviews = sheet.get_all_records()
Я действительно хочу подключиться к электронной таблице Google.
Моя система - Мохаве, не знаю, влияет ли это. СПАСИБО за помощь.