0

我已经设置了一个 Django 容器以及一个在 docker-compose 中运行的 MockServer 容器。我可以使用邮递员很好地访问 MockServers 的端点,但是当从 python 容器发出请求时,我得到一个错误:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=1080): Max retries exceeded with url: /devices (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6d83e4fa60>: Failed to establish a new connection: [Errno 111] Connection refused'))

这是我的 MockServer.properties:

mockserver.maxSocketTimeout=120000
mockserver.dynamicallyCreateCertificateAuthorityCertificate=true
mockserver.directoryToSaveDynamicSSLCertificate=.
mockserver.sslCertificateDomainName=localhost
mockserver.sslSubjectAlternativeNameDomains=www.example.com,www.another.com
mockserver.sslSubjectAlternativeNameIps=127.0.0.1


mockserver.enableCORSForAPI=true
mockserver.enableCORSForAllResponses=true
mockserver.corsAllowHeaders=Cache-Control, Postman-Token, Host, User-Agent, Accept, Accept-Encoding, Connection, Allow, Content-Encoding, Content-Length, Content-Type, ETag, Expires, Last-Modified, Location, Server, Vary, Authorization
mockserver.corsAllowMethods=CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, PATCH, TRACE
mockserver.corsAllowCredentials=true

我执行请求的代码如下所示:

return requests.get(
        URL + 'devices',
        headers={'Content-Type': 'application/json', 'Authorization': 'Basic ' + auth.decode('utf-8')}
    )

MockServer url 是 http://localhost:1080,它在使用任何其他外部 url 时都有效。

知道什么会导致这种情况吗?

4

0 回答 0