【发布时间】:2019-11-22 23:56:21
【问题描述】:
我正在从我的终端调用一个函数,该函数连接到 Google Maps API 以返回某个地点的坐标。
但是,我收到了这个错误
sock.connect((self.host, self.port))
TimeoutError: [Errno 60] Operation timed out
流程如下:
>>>> python
>>>> from geocode import getGeocodeLocation
>>>> getGeocodeLocation("New York")
错误:
sock.connect((self.host, self.port))
TimeoutError: [Errno 60] Operation timed out
我使用的代码如下 geocode.py - 我认为这没有问题,因为它之前运行良好。
import httplib2
import json
def getGeocodeLocation(inputString):
# Use Google Maps to convert a location into Latitute/Longitute coordinates
google_api_key = "my_api_key"
locationString = inputString.replace(" ", "+")
url = ('https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s'% (locationString, google_api_key))
h = httplib2.Http()
result = json.loads(h.request(url,'GET')[1])
latitude = result['results'][0]['geometry']['location']['lat']
longitude = result['results'][0]['geometry']['location']['lng']
return (latitude,longitude)
有什么想法可能是错的吗?
【问题讨论】:
标签: python google-maps google-api