I have a simple server written in Python that listens for HTTP requests and, depending on the details, may make HTTP requests of its own as part of handling the one it received. The requests my server makes are a few layers of abstraction away, but ultimately are made with the regular old requests library.
When running the server from the command line, this works fine. I'm now trying to create a systemd service for it, but it's no longer able to create HTTP requests. All other functionality seems to be working, but the requests fail, spitting out a big ugly error.
I've included my .service file and logs from a failed HTTP request. The hostname and the path to the script are obviously doctored but everything relevant is left untouched. I don't believe that any details of the code should be relevant, since it's just a normal requests request, but I can provide more details if necessary. Any insight as to why these requests are failing would be greatly appreciated.
framework-server.service:
[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
Error log when trying to send a GET request to 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',))