我有一个访问Google oauth API的码头工人图像。以下是我的代码:
from google.oauth2 import service_account
creds = service_account.Credentials.from_service_account_file(self.key_file)
scoped = creds.with_scopes(self.gcp_scope)
self.gcp_session = requests.AuthorizedSession(scoped)
credentials = service_account.Credentials.from_service_account_file(self.key_file, scopes=GCP_SCOPE)
self.set_gcp_session()
res = self.gcp_session.get("{}/{}".format(GET_PROJECT_NUMBER_URL, credentials.project_id))
在代码的最后一行,出现以下错误:
HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f4f751e8110>: Failed to establish a new connection: [Errno -3] Try again'))
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 157, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 61, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/local/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again
现在,这在CentOS和Windows主机上都可以正常工作。因此,我认为Ubuntu中存在一些网络问题。
我尝试从docker访问互联网。可从docker访问Internet。
我在这里想念什么?