id访问Google地图时出现HTTP错误403

id访问Google地图时出现HTTP错误403

本文介绍了使用api_id访问Google地图时出现HTTP错误403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算在Python中使用软件包googlemaps,并且遇到了api_id问题。

以下代码:

  from googlemaps import GoogleMaps 
gmaps = GoogleMaps(api_key ='AIzaSyDjuqAztMNv_TgGdQMdpjMo68x9eNbEl-E')
address ='Constitution Ave NW&华盛顿特区第10街西北$
lat,lng = gmaps.address_to_latlng(地址)
print lat,lng

错误信息如下:

  C:\ Users \ Linfeng \ AppData\Local\Enthought\Canopy\App\appdata\canopy-1.1.0.1371.win-x86_64\lib\urllib2.pyc http_error_default(self,req,fp,code,msg,hdrs) 
525 class HTTPDefaultErrorHandler(BaseHandler):
526 def http_error_default(self,req,fp,code,msg,hdrs):
- > 527 raise HTTPError(req.get_full_url(),code,msg,hdrs,fp)
528
529 class HTTPRedirectHandler(BaseHandler):
HTTPError:HTTP Error 403:Forbidden

我已经在Google上打开了所有与地图相关的服务。

该软件包是否过旧,因此不受Google支持?



感谢您的帮助!

一切顺利,

- 林峰

解决方案

我和你面对同样的错误,并没有找到令人满意的答案,所以我改变我的脚本遵循这个网站上的这个方法来创建我需要的脚本( - 但是用法语写的)

  import urllib ,json,csv 

def geocode(addr):
url =http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor= false%(urllib.quote(addr.replace('','+')))
data = urllib.urlopen(url).read()
info = json.loads(data)。 get(results)[0] .get(geometry)。get(location)
#有点丑陋我承认,但我接受所有建议:)'''
返回信息

#打开广告的列表文件回到寻找相应的经纬度。
f = open('list','rb')
addresses = f.readlines()
f.close()

#Loop地址和输出lat& LNG。
for a address:
r = geocode(a)
print%s%s%(r ['lat'],r ['lng'])

它对我来说很好,除了我必须修复的索引bug。


I am planning to use the package "googlemaps" in Python and had trouble with the api_id.

The following codes:

from googlemaps import GoogleMaps
gmaps = GoogleMaps(api_key = 'AIzaSyDjuqAztMNv_TgGdQMdpjMo68x9eNbEl-E')
address = 'Constitution Ave NW & 10th St NW, Washington, DC'
lat, lng = gmaps.address_to_latlng(address)
print lat, lng

The error message is as follows:

C:\Users\Linfeng\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.1.0.1371.win-x86_64\lib\urllib2.pyc in http_error_default(self, req, fp, code, msg, hdrs)
    525 class HTTPDefaultErrorHandler(BaseHandler):
    526     def http_error_default(self, req, fp, code, msg, hdrs):
--> 527         raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    528
    529 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden

I've opened all the services on Google that has to do with the maps already.

Is that package too old and therefore were not supported by Google?

Thanks for your help!

All the best,

-Linfeng

解决方案

I faced the same error as you, and didn't find a satisfying answer, so I changed my script following this method found on this site to create the script I needed (http://www.portailsig.org/content/python-geocodage-geolocalisation -- However written in french)

import urllib, json, csv

def geocode(addr):
    url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false" %   (urllib.quote(addr.replace(' ', '+')))
    data = urllib.urlopen(url).read()
    info = json.loads(data).get("results")[0].get("geometry").get("location")
    #A little ugly I concede, but I am open to all advices :) '''
    return info

#Open the List file of adresses to look for corresponding lat and lng.
f = open('list', 'rb')
addresses = f.readlines()
f.close()

#Loop to feed the func with adresses and output the lat & lng.
for a in addresses:
    r = geocode(a)
    print "%s %s" % (r['lat'], r['lng'])

It works fine for me, except index bug sometimes that I have to fix.

这篇关于使用api_id访问Google地图时出现HTTP错误403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:22