5

I'm trying to deploy code to a server to which I don't have root access. So the solution I was thinking was to deploy using pyinstaller and staticx.

My code runs in python 3.7, in a nutshell, does something like:

import requests
response = requests.get('http://example.com/api/action')
# Do something with the response

When I run it in my environment, even after "building" with pyinstaller and staticx, it works flawlessly.

However, when I try to deploy it (the server is running Red Hat Enterprise Linux Server release 7.4, which does not have python 3), I get:

Traceback (most recent call last):
  File "site-packages/urllib3/connection.py", line 160, in _new_conn
  File "site-packages/urllib3/util/connection.py", line 57, in create_connection
  File "socket.py", line 748, in getaddrinfo
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "site-packages/urllib3/connectionpool.py", line 603, in urlopen
  File "site-packages/urllib3/connectionpool.py", line 355, in _make_request
  File "http/client.py", line 1229, in request
  File "http/client.py", line 1275, in _send_request
  File "http/client.py", line 1224, in endheaders
  File "http/client.py", line 1016, in _send_output
  File "http/client.py", line 956, in send
  File "site-packages/urllib3/connection.py", line 183, in connect
  File "site-packages/urllib3/connection.py", line 169, in _new_conn
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f912ca96f28>: 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 "site-packages/requests/adapters.py", line 449, in send
  File "site-packages/urllib3/connectionpool.py", line 641, in urlopen
  File "site-packages/urllib3/util/retry.py", line 399, in increment
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='someserver.com', port=80): Max retries exceeded with url: /api/action (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f912ca96f28>: Failed to establish a new connection: [Errno -2] Name or service not known'))

Everything works if I use IP addresses instead of domains. Unfortunately, it's not a possibility because I have to hit an proxy that uses hosts. Also IP addresses may change in the future.

The server resolves names perfectly fine if I use nslookup or ping.

Any ideas why this could be happening? Any alternatives on how I could deploy my code in a way that it works in the remote server may also be a valid answer. Note however:

  • I have no root access and requesting the installation of python3, any libs or any other package such as docker, etc would most likely be rejected by my customer
  • The server can resolve external names, such as google.com but does not have access to the outer internet (the code is ment to work on internal servers, with internal DNS such as someserver.mycustomer.example)
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
JuanXarg
  • 428
  • 2
  • 11
  • Can you resolve (`dig`/`host`) the hostname used in your script? Is that actual backtrace, because it appears your `requests.get()` call is directed to `someserver.com` which sounds possible wrong / example code? – Ondrej K. Sep 05 '19 at 07:56
  • Indeed it is example code. My actual code uses an internal domain name that I cannot publish here. But yes, dig and nslookup can resolve the name. – JuanXarg Sep 05 '19 at 17:37
  • Hey there, did you ever find a solution for this? I have the exact same problem :( – Dunski May 04 '21 at 11:57

0 Answers0