Python urllib2 和连接在谷歌地图地理编码上被拒绝
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码没问题。我认为您刚刚超出了:Google 地理编码限制
Code is fine. I think you just exceed: Google geocoding limits