【问题标题】:geopy openmapquest for Python throws GeocoderInsufficientPrivileges error用于 Python 的 geopy openmapquest 引发 GeocoderInsufficientPrivileges 错误
【发布时间】:2015-10-07 21:42:24
【问题描述】:

我正在运行以下命令:

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

my_key_here 是我的 mapquest 消费者密钥,我收到以下错误:

GeocoderInsufficientPrivileges:HTTP 错误 403:禁止

不知道我做错了什么。

谢谢!

【问题讨论】:

    标签: python mapquest geopy


    【解决方案1】:

    我也尝试过相同的结果。检查库后,我发现该错误是指构建请求的行,并且似乎未传输 API 密钥。如果在 init 语句中不添加任何键,则 api_key='' 所以我尝试将我自己的文件库中的第 66 行:https://github.com/geopy/geopy/blob/master/geopy/geocoders/openmapquest.py 更改为我的键。

    还是没有成功!密钥本身有效,我通过调用库中也调用的 URL 对其进行了测试: http://open.mapquestapi.com/nominatim/v1/search.php?key="MY_KEY"&format=json&json_callback=renderBasicSearchNarrative&q=westminster+abbey

    不知道为什么这不起作用……

    干杯.kg

    【讨论】:

      【解决方案2】:

      我在修复这个问题上取得了一些进展。我能够正确编写查询,但它的 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 函数工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多