I am trying to develop something which involves finding distance between two geo locations.
There are many such combinations of source and destination, which I am passing into google distance API in a loop.
Part of my code:
key_list = [****,****,....] #google key list
base_url = 'https://maps.googleapis.com/maps/api/distancematrix/json?'
for i in geocodes:
for j in key_list:
origin_part = 'origins=' + i[0] + "," + i[1]
destination_part = '&destinations=' + i[2] + "," + i[3]
api_url = base_url + origin_part + destination_part + key
json_response = requests.get(api_url,timeout=10).json()
if json_response["status"] == "OVER_QUERY_LIMIT":
j += 1
i -= 1
This is only a part of my code.
geocodes
is a nested list containing sublists
[[source_latitude,source_longitude,destination_latitude,destination_longitude],....]
The code is running fine for sometime, but after some time, it is giving me an error saying that:
HTTPSConnectionPool(host='maps.googleapis.com', port=443): Max retries exceeded with url: /maps/api/distancematrix/json?origins=xx,xx&destinations=xx,xx&key=xxxxx
(Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f53350c50f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
I tried using sessions too instead of requests, but the same error is coming.
I want to know what is causing this issue?
And how can I rectify it, better without using try-catch
.