gpt4 book ai didi

python - Gspread,PythonAnywhere : "OSError: [Errno 101] Network is unreachable" - Trying to Connect to Google Sheets

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:40 25 4
gpt4 key购买 nike


scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('NFL Redraft-e021dc0d5969.json', scope)
客户 = gspread.authorize(creds)

此代码在我的本地机器上运行良好,但在 PythonAnywhere 上运行失败,出现 OSError: [Errno 101] Network is unreachable

知道如何解决吗?我尝试运行它的 10 次中有 1 次确实有效。我已经尝试过控制台和 ipython。 Gspread 和 Praw 是最新的。

OSError                                   Traceback (most recent call last)
<ipython-input-1-148cc5cb6e1b> in <module>()
1303 players, draft_pick_assignments, ordered_picks, positions = initialize_draft()
1304 pick_string, round_up, pick_up = pick_up_next()
-> 1305 x, x, x, comments, messages = authenticate_google()
1306 comments_replied_to = restore_from_sheets(comments)
1307 messages_processed = restore_from_sheets(messages)
<ipython-input-1-148cc5cb6e1b> in authenticate_google()
39 scope = ['https://spreadsheets.google.com/feeds']
40 creds = ServiceAccountCredentials.from_json_keyfile_name('NFL Redraft-e021dc0d5969.json', scope)
---> 41 client = gspread.authorize(creds)
42
43 sht = client.open("Redraft Test")
/home/jj2807/.local/lib/python3.5/site-packages/gspread/client.py in authorize(credentials)
400 """
401 client = Client(auth=credentials)
--> 402 client.login()
403 return client
/home/jj2807/.local/lib/python3.5/site-packages/gspread/client.py in login(self)
59
60 http = httplib2.Http()
---> 61 self.auth.refresh(http)
62
63 self.session.add_header('Authorization', "Bearer " + self.auth.access_token)

/usr/local/lib/python3.5/dist-packages/oauth2client/client.py in refresh(self, http)
558 request.
559 """
--> 560 self._refresh(http.request)
561
562 def revoke(self, http):

/usr/local/lib/python3.5/dist-packages/oauth2client/client.py in _refresh(self, http_request)
763 """
764 if not self.store:
--> 765 self._do_refresh_request(http_request)
766 else:
767 self.store.acquire_lock()

/usr/local/lib/python3.5/dist-packages/oauth2client/client.py in _do_refresh_request(self, http_request)
795 logger.info('Refreshing access_token')
796 resp, content = http_request(
--> 797 self.token_uri, method='POST', body=body, headers=headers)
798 content = _helpers._from_bytes(content)
799 if resp.status == http_client.OK:

/usr/local/lib/python3.5/dist-packages/httplib2/__init__.py in request(self, uri, method, body, headers, redirections, connection_type)
1312 content = b""
1313 else:
-> 1314 (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
1315 except Exception as e:
1316 if self.force_exception_to_status_code:

/usr/local/lib/python3.5/dist-packages/httplib2/__init__.py in _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)
1062 auth.request(method, request_uri, headers, body)
1063
-> 1064 (response, content) = self._conn_request(conn, request_uri, method, body, headers)
1065
1066 if auth:

/usr/local/lib/python3.5/dist-packages/httplib2/__init__.py in _conn_request(self, conn, request_uri, method, body, headers)
985 try:
986 if conn.sock is None:
--> 987 conn.connect()
988 conn.request(method, request_uri, body, headers)
989 except socket.timeout:

/usr/lib/python3.5/http/client.py in connect(self)
1250 "Connect to a host on a given (SSL) port."
1251
-> 1252 super().connect()
1253
1254 if self._tunnel_host:

/usr/lib/python3.5/http/client.py in connect(self)
847 """Connect to the host and port specified in __init__."""
848 self.sock = self._create_connection(
--> 849 (self.host,self.port), self.timeout, self.source_address)
850 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
851

/usr/lib/python3.5/socket.py in create_connection(address, timeout, source_address)
709
710 if err is not None:
--> 711 raise err
712 else:
713 raise error("getaddrinfo returns an empty list")

/usr/lib/python3.5/socket.py in create_connection(address, timeout, source_address)
700 if source_address:
701 sock.bind(source_address)
--> 702 sock.connect(sa)
703 return sock
704

最佳答案

您使用的是预装在 PythonAnywhere 上的旧版 gspread,它无法识别代理设置,因此您无法连接。尝试使用更新版本的 gspread。

关于python - Gspread,PythonAnywhere : "OSError: [Errno 101] Network is unreachable" - Trying to Connect to Google Sheets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44786983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com