我在python中使用此代码来从Google API位置搜索获取位置 .
import urllib.request
import json
googleGeocodeUrl = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=&types=store&hasNextPage'
keyword = "hospital"
geolocation = "&location=10.7626,106.660&radius=500"
APIKEY = '&key='+'AIzaSyCgAPKq_323R5qM7O-_IpsWzbFYg5v17Ik'
url = googleGeocodeUrl + keyword + geolocation + APIKEY
print(url)
url = googleGeocodeUrl + keyword + geolocation + APIKEY
json_response = urllib.request.urlopen(url)
search = json_response.read()
searchjson = json.loads(search)
export = open('hospital.csv','w')
for place in searchjson['results']:
print(place['name'])
print(place['geometry']['location'])
export.write(place['name']+','+str(place['geometry']['location']['lng'])\
+','+str(place['geometry']['location']['lat'])+'\n')
export.close()
它返回给我这个错误:
UnicodeEncodeError: 'charmap' codec can't encode character '\u1eed' in position 1: character maps to undefined
我怎样才能解决这个问题?