Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
geopy openmapquest for Python引发GeocoderInsufficientPrivileges错误_Python_Mapquest_Geopy - Fatal编程技术网

geopy openmapquest for Python引发GeocoderInsufficientPrivileges错误

geopy openmapquest for Python引发GeocoderInsufficientPrivileges错误,python,mapquest,geopy,Python,Mapquest,Geopy,我正在运行以下程序: import geopy geolocator = geopy.geocoders.OpenMapQuest(api_key='my_key_here') location1 = geolocator.geocode('Madrid') 其中,我的密钥这里是我的mapquest用户密钥,我得到以下错误: GeoCoderSufficientPrivileges:HTTP错误403:禁止 不知道我做错了什么 谢谢 我也尝试过同样的方法,但效果相同。在检查了库之后,我发现错误

我正在运行以下程序:

import geopy
geolocator = geopy.geocoders.OpenMapQuest(api_key='my_key_here')
location1 = geolocator.geocode('Madrid')
其中,我的密钥这里是我的mapquest用户密钥,我得到以下错误:

GeoCoderSufficientPrivileges:HTTP错误403:禁止

不知道我做错了什么


谢谢

我也尝试过同样的方法,但效果相同。在检查了库之后,我发现错误是指请求生成的行,似乎API键没有被传输。如果在init语句中不添加任何键,则api_key='',因此我尝试将我自己的文件库中的第66行:更改为我的键

还是没有成功!密钥本身可以工作,我通过调用库中也调用的URL对其进行了测试: “我的钥匙”&format=json&json\u callback=renderbasicsearchrantative&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
现在的任务仍然是让
\u parse\u json
函数工作