: 无法建立新连接:[Errno 111] Connection denied'),python"/>

首页 > 解决方案 > 连接错误(': 无法建立新连接:[Errno 111] Connection denied')

问题描述

我正面临 FHIR_parser 使用的 urllib 连接错误。此错误发生在对接受患者 ID 的端点的 GET 请求中。链接到存储库:https ://github.com/greenfrogs/FHIR-Parser

请求 - 2.24.0,urllib3 版本:1.25.10,python:3.7

>> from fhir_parser import FHIR
>> fhir = FHIR()
>> patient = fhir.get_patient('8f789d0b-3145-4cf2-8504-13159edaa747')

连接错误

Error
Traceback (most recent call last):
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connection.py", line 309, in connect
conn = self._new_conn()
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f3a5d760390>: 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/joel/.local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/joel/.local/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='localhost', port=5001): Max retries exceeded with url: /api/Patient/8f789d0b-3145-4cf2-8504-13159edaa747 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3a5d760390>: 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 "", line 1, in
File "/home/joel/.local/lib/python3.7/site-packages/fhir_parser/fhir.py", line 73, in get_patient
response = requests.get(urllib.parse.urljoin(self.endpoint, 'Patient/' + str(id)), verify=self.verify_ssl)
File "/home/joel/.local/lib/python3.7/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/home/joel/.local/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/joel/.local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/home/joel/.local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/home/joel/.local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='localhost', port=5001): Max retries exceeded with url: /api/Patient/8f789d0b-3145-4cf2-8504-13159edaa747 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3a5d760390>: Failed to establish a new connection: [Errno 111] Connection refused'))

标签: python

解决方案


这个库只是一个 FHIR 客户端,没有服务器。因此,您必须提供 FHIR 服务器的地址/URL,默认情况下它希望服务器在本地主机和端口 5001 上运行,并使用类似https://localhost:5001/api/. 或者您需要自己在本地主机上运行 FHIR 服务器。

from fhir_parser import FHIR
fhir = FHIR(endpoint = 'https://SomeServer.com:SomePort/api/')
print(fhir.get_patient('8f789d0b-3145-4cf2-8504-13159edaa747'))

推荐阅读