# -*- coding: utf-8 -*-
from geopy.geocoders import Nominatim
geolocator = Nominatim()
place = 'Greece'
location = geolocator.geocode(place)
print location
错误:
Traceback (most recent call last):
File "C:/temp/Test.py", line 10, in <module>
print location
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
第二次尝试解码:
# -*- coding: utf-8 -*-
from geopy.geocoders import Nominatim
geolocator = Nominatim()
place = 'Greece'
place_decoded = place.decode('utf-8')
location = geolocator.geocode(place)
print location
错误:
Traceback (most recent call last):
File "C:/temp/Test.py", line 10, in <module>
print location
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
检查 place_decoded 的类型:
print type(place_decoded)
<type 'unicode'>
希腊这个词不应该带来任何麻烦。有人有想法吗?