I have a problem that I am not sure how to solve. I want to iterate through a file where I want to convert the coordinates to the geolocation address.The code works fine but after it iteretes through a certain number of lines in the file the problem occurs.
from __future__ import print_functionfrom geopy.geocoders import Nominatimfrom shapely.wkt import loads as load_wktfrom shapely.geometry import Point, Polygonimport ioimport reimport astimport timegeolocator = Nominatim()with io.open('sample_test2.txt', encoding="utf-8") as f, io.open('sample_test3.txt', 'w',encoding="utf-8") as g: for line in f: m = re.sub(r'(70[0-9]+,).*', r'\1', line.rstrip()) z = re.sub(r'.*POINT \([0-9]+.[0-9]+ -[0-9]+.[0-9]+\)(.*)', r'\1', line.rstrip()) c = re.sub(r'.*POINT \(([0-9]+.[0-9]+) (-[0-9]+.[0-9]+)\).*', r'"\1, \2"', line.rstrip()) k = ast.literal_eval(c) location = geolocator.reverse(k, timeout=60) h = location.address j = re.sub(r'.*, ([^,]+, [^,]+), [0-9]+, United.*', r'\1', h.rstrip()) print (m, j, z, file = g)f.close()g.close()Now I read from some other questions that I should usetime.sleep(). Now I wanted to put it before theprint. The first time I run my code (withouttime.sleep()) it came to around 1800 lines that he converted before getting this error:
raise GeocoderServiceError(message)geopy.exc.GeocoderServiceError: HTTP Error 429: Too Many RequestsBut now with or without thetime.sleep() it doesn't even do the first line it just breaks from the beginning with the error. Any idea what to do?
- jackmaney.com/2015/01/09/geocoding-rate-limited-queuePadraic Cunningham– Padraic Cunningham2016-06-25 21:45:32 +00:00CommentedJun 25, 2016 at 21:45
- What is the differnece between this code and that I put a time.sleep(0.1)like I read the code it limits it at 10 per second, with time.sleep(0.1) I do the same or?Vedad– Vedad2016-06-28 08:03:09 +00:00CommentedJun 28, 2016 at 8:03
- stackoverflow.com/a/51573613/8884513KostyaEsmukov– KostyaEsmukov2018-07-28 17:20:36 +00:00CommentedJul 28, 2018 at 17:20