geopy openmapquest for Python抛出GeocoderInsufficientPrivileges

2024-09-26 18:17:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行以下内容:

import geopy
geolocator = geopy.geocoders.OpenMapQuest(api_key='my_key_here')
location1 = geolocator.geocode('Madrid')

其中my_key_here是mapquest的使用者密钥,我得到以下错误:

GeocoderInsufficientPrivileges: HTTP Error 403: Forbidden

不知道我做错了什么。在

谢谢!在


Tags: keyimportapiheremy密钥使用者geocode
2条回答

我也试过同样的方法,结果也一样。在检查了库之后,我发现错误引用了请求所在的行,而且看起来,API密钥没有被传输。如果在init语句中没有添加键,那么api_key='',所以我试图将我自己的文件库中的第66行改为我的键。在

还是没有成功!密钥本身有效,我通过调用库中调用的URL进行了测试: http://open.mapquestapi.com/nominatim/v1/search.php?key=“我的密钥”&format=json&json\u callback=renderbasicsearch叙事&q=westminster+abbey

不知道为什么这样不行

在干杯.kg在

我修好这个有点进步。我能够正确地编写查询,但是json解析有点让我为难。也许有人知道。我知道url被正确地发送了(我在浏览器中检查了它,它返回了一个json对象)。也许有人知道如何解析返回的json对象,使其最终工作。在

无论如何,我必须进入openmapquest.py源代码,从第66行开始,我做了以下修改:

    self.api_key = api_key
    self.api = "http://www.mapquestapi.com/geocoding/v1/address?"

def geocode(self, query, exactly_one=True, timeout=None): # pylint: disable=W0221
    """
    Geocode a location query.

    :param string query: The address or query you wish to geocode.

    :param bool exactly_one: Return one result or a list of results, if
        available.

    :param int timeout: Time, in seconds, to wait for the geocoding service
        to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
        exception. Set this only if you wish to override, on this call
        only, the value set during the geocoder's initialization.

        .. versionadded:: 0.97
    """
    params = {
        'key': self.api_key,
        'location': self.format_string % query
    }
    if exactly_one:
        params['maxResults'] = 1
    url = "&".join((self.api, urlencode(params)))
    print url # Print the URL just to make sure it's produced correctly

现在任务仍然是让_parse_json函数工作。在

相关问题 更多 >

    热门问题