简体   繁体   English

来自Google Cloud Platform的Python请求失败(应用引擎和Cloud Shell)

[英]Python request fails from google cloud platform (app engine & cloud shell)

I have a very simple python http request which works on my local machine, but does not work in google app engine or from the google cloud shell. 我有一个非常简单的python http请求,该请求可在我的本地计算机上运行,​​但不适用于google app引擎或google cloud shell。 There must be config that is messing with the request, but I can't seem to find the problem. 必须有配置弄乱了请求,但我似乎找不到问题。

I am using python 3.7 我正在使用python 3.7

The code that causes the exception is the following (I have replaced the actual URL by example.com) 导致异常的代码如下(我已经用example.com替换了实际的URL)

(The service I need to call is listening on port 6123) (我需要呼叫的服务正在侦听端口6123)

import requests
myrequest = requests.get("http://example.com:6123/something?param=123")

The full error message I get is the following: 我收到的完整错误消息如下:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 184, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f0b242cd710>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='example.com', port=6123): Max retries exceeded with url: /something?param=123 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f0b242cd710>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='example.com', port=6123): Max retries exceeded with url: /something?param=123 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f0b242cd710>: Failed to establish a new connection: [Errno -2] Name or service not known'))

Domain is not available from the outside, only from local network. 域不能从外部访问,只能从本地网络访问。 Thanks Dustin Ingram! 谢谢达斯汀·英格拉姆!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从python + flask + gunicorn + nginx + Compute Engine应用程序中读取来自Google Cloud Storage的文件失败 - Reading of a file from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app 无法在Google App Engine和Python上显示来自云存储的图像 - Trouble displaying image from cloud storage on Google App Engine, Python 带有python的Google App Engine数据存储标签云 - Google app engine datastore tag cloud with python 在Google App / Cloud Engine中避免使用Python全局变量 - Avoiding Python globals in Google App/Cloud Engine 谷歌云平台对Django app的响应 - Response from Google Cloud Platform to Django app 简单的Google Cloud部署:将Python文件从Google Cloud存储库复制到应用程序引擎 - Simple Google Cloud deployment: Copy Python files from Google Cloud repository to app engine 如何列出所有应用程序以使用 python API 在谷歌云平台的应用程序引擎上获取 appID - How to list all apps to get appID on app engine in google cloud platform using python API 是否可以使用 App Engine 通过 Google Cloud Platform 上的本地路径从云存储桶对象加载文件? - Is it possible to load a file from a cloud storage bucket object by its local path on Google Cloud Platform using App Engine? 在ML Engine作业中从培训师那里获取状态(Google Cloud Platform) - Get status from trainer in ML Engine job (Google Cloud Platform) 从 Google App Engine 上的 web 应用程序调用 Google Cloud function? - Calling a Google Cloud function from a web app on Google App Engine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM