Oct-13-2020, 05:25 AM
Hello. I am using requests library to make API requests from the internal server. I have noticed that every now and then maybe like (1/20) chance my program stops when I try to make a GET request and I am not sure how to solve this problem.
The error message:
The last lines of error message indicae that the max tries are exceeded for the request. But why does it happen just occasionally and how to fix it? The request function:
I know that the error appears after calling a function below:
Because the debug print statement is not executed after that function.
Any tips and ideas on what could be wrong here are appreciated! Please help me find the problem
The error message:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
Exception in Tkinter callback 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 0xafd25750 >: 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 = 'factory.teltonika.lt' , port = 443 ): Max retries exceeded with url: / gorapi / v2 / 279c82f4 - 1f45 - 4f4e - bdd2 - 944c3137d482 / boxes / tree / 9BE9A4CD - 813C - 4F48 - 837E - D101939F5174 (Caused by NewConnectionError( '<urllib3.connection.VerifiedHTTPSConnection object at 0xafd25750>: 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.7/tkinter/__init__.py" , line 1705 , in __call__ return self .func( * args) File "/usr/lib/python3.7/tkinter/__init__.py" , line 749 , in callit func( * args) File "/home/pi/Desktop/lukas_programming/PTL_python/PTL_multiple_picks.py" , line 718 , in Scanning_operation Parse_GUID(user_input) File "/home/pi/Desktop/lukas_programming/PTL_python/PTL_multiple_picks.py" , line 921 , in Parse_GUID response_get_box_info = requests.get(URL_get_box_info) 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 = 'factory.teltonika.lt' , port = 443 ): Max retries exceeded with url: / gorapi / v2 / 279c82f4 - 1f45 - 4f4e - bdd2 - 944c3137d482 / boxes / tree / 9BE9A4CD - 813C - 4F48 - 837E - D101939F5174 (Caused by NewConnectionError( '<urllib3.connection.VerifiedHTTPSConnection object at 0xafd25750>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution' )) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
def Parse_GUID(guid): global komplektacijos_Serial global komplektacijos_Imei global komplektacijos_ID global user_input response_get_box_info = requests.get(URL_get_box_info) print ( "response get box info status code=" ,response_get_box_info.status_code) if (response_get_box_info.status_code = = 200 ): parsed_guid = response_get_box_info.json() komplektacijos_ID = parsed_guid[ 'Code' ] komplektacijos_Serial = parsed_guid[ 'Products' ][ 0 ][ 'SerialNumber' ] komplektacijos_Imei = parsed_guid[ 'Products' ][ 0 ][ 'Imei' ] user_input = komplektacijos_ID # komplektacijos_ID comes from parse_GUID gaminio_kodas = komplektacijos_ID + ".csv" create_image_folder(komplektacijos_Serial,komplektacijos_ID) return else : time.sleep( 1 ) Parse_GUID(user_input) |
1 |
response_get_box_info = requests.get(URL_get_box_info) |
Any tips and ideas on what could be wrong here are appreciated! Please help me find the problem