我正在尝试开发客户端服务器应用程序,但遇到了一些问题。我的两个服务都是在单独的 docker 容器中本地开发的。
客户端使用 api 从 api 获取数据requests
python 库。它可以在生产中使用,但在本地,我无法使用:
requests.get("http://localhost:PORT/ENDPOINT")
它不断地给我回馈:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=4000): Max retries exceeded with url: /data (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f352ccd42b0>: Failed to establish a new connection: [Errno 111] Connection refused'))
我有什么遗漏的吗?
经过进一步研究,我找到了答案here https://github.com/HTTP-APIs/hydra-python-agent/issues/104。基本上,在本地使用 Docker 时,您只需运行:
requests.get("http://host.docker.internal:PORT/ENDPOINT")
代替localhost
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)