HTTP 요청을 수신하고 세부 사항에 따라 들어오는 요청을 처리하는 과정의 일부로 자체 HTTP 요청을 생성할 수 있는 Python으로 작성된 간단한 서버가 있습니다. 내 서버가 수행하는 요청은 여러 계층의 추상화이지만 궁극적으로는 requests
일반 오래된 라이브러리를 사용하여 수행됩니다.
이는 명령줄에서 서버를 실행할 때 효과적입니다. 이제 이에 대한 시스템 서비스 생성을 시도했지만 더 이상 HTTP 요청을 생성할 수 없습니다. 다른 모든 기능은 제대로 작동하는 것처럼 보이지만 요청이 실패하고 크고 보기 흉한 오류가 발생합니다.
내 .service 파일과 실패한 HTTP 요청 로그를 포함했습니다. 호스트 이름과 스크립트 경로는 분명히 수정되었지만 관련된 모든 것은 동일하게 유지됩니다. 이는 일반적인 요청이므로 코드의 세부정보가 관련성이 없어야 한다고 생각 requests
하지만 필요한 경우 더 자세한 내용을 제공할 수 있습니다. 이러한 요청이 실패한 이유에 대한 통찰력을 가지시면 대단히 감사하겠습니다.
프레임워크 서버.서비스:
[Unit]
Description=Run server for testing framework
[Service]
WorkingDirectory=/path/to/my/script
Environment=PYTHONUNBUFFERED=1
User=username
Group=username
Restart=on-failure
RestartSec=5
ExecStart=/usr/bin/env python3 server.py
SyslogIdentifier=server.py
[Install]
WantedBy=multi-user.target
GET 요청을 보내려고 할 때 오류 로그 my.request.url/index.php?/api/v2/get_case/4887104
:
Exception happened during processing of request from ('10.40.200.106', 56051)
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 144, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 852, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 298, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 153, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7fb3bcd36208>: 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/lib/python3/dist-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='my.request.url', port=443): Max retries exceeded with url: /index.php?/api/v2/get_case/4887104 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fb3bcd36208>: 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/lib/python3.6/socketserver.py", line 320, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
self.handle()
File "/usr/lib/python3.6/http/server.py", line 418, in handle
self.handle_one_request()
File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
method()
File "server.py", line 194, in do_POST
test_handler.run_tests(run_id, project_id, suite_id, case_id, test_ids)
File "/path/to/my/script/lib/testing_automation/testrail_integration/test_handler.py", line 70, in run_tests
my_case = client.get_case(case_id)
File "/path/to/my/script/lib/testing_automation/testrail_integration/testrail_wrapper.py", line 68, in get_case
return super().send_get(f'get_case/{case_id}')
File "/path/to/my/script/lib/testing_automation/testrail_integration/testrail.py", line 41, in send_get
return self.__send_request('GET', uri, filepath)
File "/path/to/my/script/lib/testing_automation/testrail_integration/testrail_wrapper.py", line 48, in _APIClient__send_request
return super()._APIClient__send_request(method, uri, data)
File "/path/to/my/script/lib/testing_automation/testrail_integration/testrail.py", line 79, in __send_request
response = requests.get(url, headers=headers)
File "/usr/lib/python3/dist-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 520, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 630, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='my.request.url', port=443): Max retries exceeded with url: /index.php?/api/v2/get_case/4887104 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fb3bcd36208>: Failed to establish a new connection: [Errno -2] Name or service not known',))
답변1
Jeff Schaller는 댓글에서 문제를 확인했습니다. 요청을 하는 데 필요한 프록시가 CLI 환경에 구성되어 있는데 너무 오래 전에 설정되어 있어서 필요하다는 사실을 잊어버렸습니다.
Environment=https_proxy="http://location.of.proxy"
.service 파일을 포함하여 문제를 해결했습니다.