1

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 Requests

But 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?

sideshowbarker's user avatar
sideshowbarker
89.2k30 gold badges219 silver badges216 bronze badges
askedJun 25, 2016 at 18:31
Vedad's user avatar
3

1 Answer1

1

Looks like whatever webservice you are using has blocked you, most likely via your IP address. Wait for a while and then make sure that you are being "friendly" to the service, e.g., by inserting those sleeps.

answeredJun 25, 2016 at 18:33
mrks's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way how to check what is the maximum I can convert per secund,minute,hour,day..???
They will probably have it in their documentation somewhere.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.