主机(ip 127.0.1)不在Googlengin上运行

2024-10-02 10:33:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经公开了一个URL(http://127.0.0.1:5000/daily),但是在googlecomputeengine(GCE)中,我没有得到值。如果我在简单的python程序中通过请求访问这个URL,它就会高效地运行。你知道吗

import requests
import json
req=requests.get('http://127.0.0.1:5000/daily')

a = json.loads(req.text)

discount_rate = a['data']['policy_rate']
six_months_kibor = a['data']['today_kibor_rate']
dollar_to_pkr= a['data']['today_usd_rate']

print(discount_rate, six_months_kibor, dollar_to_pkr)

我从GCE收到的错误是:

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f93526c16a0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /daily (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f93526c16a0>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    req=requests.get('http://127.0.0.1:5000/daily')
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/dev_baseh/.local/lib/python3.5/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /daily (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f93526c16a0>: Failed to establish a new connection: [Errno 111] Connection refused', )) 

我不知道原因,那就是为什么它没有通过GCE。 提前感谢:)


Tags: inpydevhomerequestlibpackageslocal
1条回答
网友
1楼 · 发布于 2024-10-02 10:33:12

IP地址127.0.0.1是指计算机的本地IP地址。如果两个python都运行在同一个服务器上,那么它的IP地址是相同的。你知道吗

当您尝试从GCP访问127.0.0.1时,发生的情况是GCP正在本地尝试访问端口5000,而不是您机器的端口5000。你知道吗

您需要找出运行服务器的计算机的面向公共的IP地址。如果它在你的电脑上,你可以通过谷歌“什么是我的IP”来获取它。你知道吗

相关问题 更多 >

    热门问题