Python Forum
Requests library failure in name resolution/Network is unreachable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Requests library failure in name resolution/Network is unreachable
#1
Hello. I am using Requests library to make API requets to the internal server/database.
I am making requests as following:
while(1):
    URL_get_box_info = "https://factory.teltonika.lt/gorapi/v2/"+session_ID+"/boxes/tree/"+guid
    response_get_box_info = requests.get(URL_get_box_info)
    print("response get box info status code=",response_get_box_info.status_code)
    time.sleep(2)
And everything seemed fine at first glance. However, as I was testing the system more and more, I have realized that ocassionally, evey 10,15 requets I am getting a "failure in name resolution" or "Connection refused" error and cannot understand what the problem is..

See the images below:
https://ibb.co/m4sFhbr
https://ibb.co/QFDbL07

I then went ahead and tried to making a request to https:/google.com, but the same problem apperas:

while(1):
    response_get_box_info = requests.get("https://google.com")
    print("response get box info status code=",response_get_box_info.status_code)
    time.sleep(2)
THe full error message:
response get box info status code= 200
response get box info status code= 200
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 57, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0xb580ee50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, 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='google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb580ee50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Desktop/lukas_programming/PTL_python/api_test.py", line 35, in <module>
    response_get_box_info = requests.get("https://google.com")
  File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb580ee50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
Just to note, when I just simply go to browser and type API url, I am getting the correct response at all times, so it makes me think that it has to do with the requests library? I really do not know how to even start debugging this problem. I have read a few forums regarding this issue but none that would solve this
Reply
#2
I have connected to the same WIFI and ran the same python script on my laptop. No problems whatsoever. So the issue is not with requests library but with the raspberry PI.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failure to run source command middlestudent 2 656 Sep-22-2023, 01:21 PM
Last Post: buran
  python requests library .JSON() error mHosseinDS86 6 3,240 Dec-19-2022, 08:28 PM
Last Post: deanhystad
  Dickey Fuller failure Led_Zeppelin 4 2,533 Sep-15-2022, 09:07 PM
Last Post: Led_Zeppelin
  Assert failure jtcostel 1 1,614 Sep-03-2021, 05:28 PM
Last Post: buran
  xml decoding failure(bs4) roughstroke 1 2,211 May-09-2020, 04:37 PM
Last Post: snippsat
  SCIKIT learn failure in mac Perja11 1 2,257 Nov-30-2019, 06:44 PM
Last Post: snippsat
Star résolution numérique pour les équations de Lockta-Volterra en python Mohamed19 2 2,199 Jul-07-2019, 01:26 PM
Last Post: SheeppOSU
  failure to find modules justus123 2 4,202 Dec-14-2018, 04:28 PM
Last Post: nilamo
  LIB install failure Able98 2 3,883 Jun-07-2017, 06:41 PM
Last Post: Able98
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,745 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020