Python urllib2 和连接在谷歌地图地理编码上被拒绝

发布于 2024-11-16 07:38:38 字数 976 浏览 2 评论 0原文

我正在使用 Google 地图 api 对地址进行简单的地理编码。

这是一个截图并得到“[Errno 61]连接被拒绝”:

import urllib2

url='http://maps.googleapis.com/maps/api/geocode/json?address=800+S.+Pacific+Coast+Hwy,+Redondo+Beach,+CA&sensor=false'
req = urllib2.Request(url)
print vars(req)
response=urllib2.urlopen(req)
the_page = response.read()

它只需在 FF 3 浏览器

php 版本中执行 GET 即可正常工作:

$url='http://maps.googleapis.com/maps/api/geocode/json?address=800+S.+Pacific+Coast+Hwy,+Redondo+Beach,+CA&sensor=false';
$result=file_get_contents($url);

var_dump($result);

并且 ruby​​ 也可以工作:

require 'net/http'

host='maps.googleapis.com'
path='/maps/api/geocode/json?address=800+S.+Pacific+Coast+Hwy,+Redondo+Beach,+CA&sensor=false'

http=Net::HTTP.new(host)
headers,body=http.get(path)
if headers.code=="200"
    print body
else
    puts "#{headers.code} #{headers.message}" 
end

有什么想法为什么 python 版本不起作用?

I am doing a simple geocoding of addresses using Google maps api.

Here is a snipped and getting a "[Errno 61] Connection refused":

import urllib2

url='http://maps.googleapis.com/maps/api/geocode/json?address=800+S.+Pacific+Coast+Hwy,+Redondo+Beach,+CA&sensor=false'
req = urllib2.Request(url)
print vars(req)
response=urllib2.urlopen(req)
the_page = response.read()

It works from just doing a GET in FF 3 browser

php version works fine:

$url='http://maps.googleapis.com/maps/api/geocode/json?address=800+S.+Pacific+Coast+Hwy,+Redondo+Beach,+CA&sensor=false';
$result=file_get_contents($url);

var_dump($result);

and ruby works too:

require 'net/http'

host='maps.googleapis.com'
path='/maps/api/geocode/json?address=800+S.+Pacific+Coast+Hwy,+Redondo+Beach,+CA&sensor=false'

http=Net::HTTP.new(host)
headers,body=http.get(path)
if headers.code=="200"
    print body
else
    puts "#{headers.code} #{headers.message}" 
end

Any ideas why the python version doesn't work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当梦初醒 2024-11-23 07:38:38

代码没问题。我认为您刚刚超出了:Google 地理编码限制

Code is fine. I think you just exceed: Google geocoding limits

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文