Hello. I am using Requests library to make API requets to the internal server/database.
I am making requests as following:
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:
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