Search code examples
pythonexceptiongeopy

GeocoderDotUS Geopy ('NoneType' object is not iterable)


import csv
from geopy import geocoders
import time

g = geocoders.GeocoderDotUS()

spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t', quotechar='|')

f = open("output.txt",'w')

for row in spamReader:
a = ', '.join(row)
#exactly_one = False
time.sleep(1)


place, (lat, lng) = g.geocode(a)


b = str(place) + "," + "[" + str(lat) + "," + str(lng) + "]" + "\n"
print b
f.write(b)

I can't really determine why I am receiving

Traceback (most recent call last): File "C:\Users\Penguin\workspace\geocode-nojansdatabase\src\yahoo.py", line 17, in place, (lat, lng) = g.geocode(a) TypeError: 'NoneType' object is not iterable

I checked to make sure there was a value in a before the geocode(a) call was placed. Perhaps a match was not found? If that is the case the I guess I just have to add in an if not b then statement. Does anyone know more about this?

I am seeing that adding a

a = ', '.join(row)
print(a)

Does yield: 178 Connection Rd Pomona QLD


Solution

  • >>> a, (b, c) = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'NoneType' object is not iterable
    >>> a, (b, c) = ('foo', None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'NoneType' object is not iterable
    

    Your guess is correct. Check before unpacking.