Using the Geopy library

0

I have the following question, I want to set up a routine to perform iterations within a dataframe (pandas) to extract longitude and latitude data, after supplying the address using the 'geopy' library.

The routine I created was:

import time
from geopy.geocoders import GoogleV3
import os

def set_proxy():
    proxy_addr = 'http://{user}:{passwd}@{address}:{port}'.format(
        user='usuario', passwd='senha', 
        address='IP', port=int('PORTA'))
    os.environ['http_proxy'] = proxy_addr
    os.environ['https_proxy'] = proxy_addr

def unset_proxy():
    os.environ.pop('http_proxy')
    os.environ.pop('https_proxy')

set_proxy()

geo_keys = ['AIzaSyBXkATWIrQyNX6T-VRa2gRmC9dJRoqzss0'] # Chave da API Google
geolocator = GoogleV3(api_key=geo_keys )

for index, row in df.iterrows():
    location = geolocator.geocode(row['NO_LOGRADOURO'])
    time.sleep(2)
    lat=location.latitude
    lon=location.longitude
    #location = geolocator.geocode('%s, %s' % (latitude, longitude), timeout=10)
    address = location.address
    unset_proxy()
    print(str(lat) + ', ' + str(lon))

The problem I'm having is that when I run the code the following error is thrown:

  

GeocoderQueryError: Your request was denied.

I tried the creation without passing the key to the google API, however, I get the following message.

  

KeyError: 'http_proxy'

and if I remove the unset_proxy() statement from inside the for, the message I get is:

  

GeocoderQuotaExceeded: The given key has gone over the limit requests in the 24 hour period or has submitted too many requests in too short a period of time.

But I only made 5 requests today, and I'm putting a 2-second sleep between requests. Should the period be longer?

Any idea what might be happening?

    
asked by anonymous 25.04.2018 / 19:36

0 answers