Python IndexError: list index out of range doesn't make sense -


I'm working on a little python code which parses the response from the Google Maps API, but "Index error: list Out of the index limit "error, which does not make sense to me for some requests, the code is working for some other people, no.

The purpose of the code is to configure the answer to a random address address and to put in any word structure for later use.

I checked for the list of categories (for example N counting to -1), but this is not a problem. Exact traceback: Tracebacks (last most recent call): File "& lt; stdin>", line 1, & lt; Module & gt; File "geoCodeAPI.py", line 67, in GetLocation data {i] = {'formatted_address'}: Formatted address [i], 'street': street name [i], 'street_number': street number [ I], 'city': city [i], 'country': country [i], 'lat': lat [i], 'lng': lng [i]} index error: out of range index index

Suggestions and general comments in any code are highly appreciated. Thank you. #! / Usr / bin / python import urlib import json jsonResponse = '' df mill location (rawaddtion string): addressString = rawAddressString.replace ("", "+"); Url = "http://maps.googleapis.com/maps/api/geocode/json?address=" + Address String + "and sensor = False"; GoogleResponse = urllib.urlopen (url); Result = json.load (googleResponse) formatted address = [] Latitude = [] LNG = [] country = [] street number = [] road name = [] city = [] results for ['result' ]: Formatted address.append (S ['formatted_address']) lat.append (s ['geometry'] ['location'] ['lat']) lng.append (s ['geometry'] ['location' Foo ['address_components']: 'foo' ['types'] [0] == "country": country.append (foo ['long_name']): country.append ( "N") if foo ['' '' road '' number '': streetnumber.append (foo ['long_name']) Other: streetnumber.append ("NA") if foo ['types'] [0] = = "Route": street name ('FO [' long_name ']) Other: street's name . Epand ("NA") If in the "terrain" AFF ['type'] [0]: city .append (foo ['long_name']) Other: city. Data in the [i] = {'formatted_address'} :) ("NA") data = dict () print range (LAN (country)) in print range (lane (city)): country [ I], 'lat': lat [i], 'street': street name [i], 'street_number': street number [i], 'city': city [i], 'country' 'lng': LNG [i]} Turn on data again

Do not know whether this is the only display There is a mistake in itself, but

  other: country.append ("NA")   

is not in the right indentation, so execute it every time The condition is, and you will have more than the list of countries in comparison to any other list ...

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -