在代理后面使用googlemaps距离矩阵python api

在代理后面使用googlemaps距离矩阵python api,python,google-maps-api-3,proxy,Python,Google Maps Api 3,Proxy,我在使用googlemaps距离矩阵函数处理代理时遇到问题。 如果没有代理,此代码可以正常工作: import googlemaps gmaps = googlemaps.Client(key=googleAPIkey) commuteData = gmaps.distance_matrix(origins, destination, mode=mode, language=language, avoid=avoid, units=units) 我尝试过这样设置代理 gmaps = g

我在使用googlemaps距离矩阵函数处理代理时遇到问题。 如果没有代理,此代码可以正常工作:

import googlemaps
gmaps = googlemaps.Client(key=googleAPIkey)    
commuteData = gmaps.distance_matrix(origins, destination, mode=mode, language=language, avoid=avoid, units=units)
我尝试过这样设置代理

gmaps = googlemaps.Client(key=googleAPIkey, requests_kwargs={'proxies':"http://<proxy server>"})
有什么建议吗? 谢谢,googlemaps客户端实际上只是将该值传递给请求。请求的代理值是一个dictionary(),该dictionary应该将协议映射到代理的URL

所以,我想你想要:

gmaps = googlemaps.Client(key=googleAPIkey, requests_kwargs={'proxies':{"http":"http://<proxy server>","https":"http://<proxy_server>"})
gmaps=googlemaps.Client(key=GoogleAppKey,requests\u kwargs={'proxies':{“http::“http://”,“https:“http://”})
(假设已设置代理,因此相同的代理端口可用于http和https)


另外:一般来说,如果您在Linux或Windows(可能还有Mac)上运行python请求,python请求会尊重环境;您应该能够这样做(在应用程序外部,或者如果您确实想通过os.environ在内部)
export http\u proxy=http://proxyserver
(或者如果未在80上收听)然后运行您的命令,而不需要对每个请求中的代理进行硬编码。

这样做了,谢谢。我讨厌花几个小时在一个问题上,却发现它是由一个简单的语法错误造成的。re:python和proxy's。是的,当我从命令行运行时,python看起来确实尊重环境变量。不过,我大部分时间都在开发Eclipse-PyDev中的ent,我发现它有各种各样的代理问题。我知道我的环境变量设置正确,我在Eclipse的网络连接中配置了相同的代理设置。有时有效,有时无效。我发现最安全的选择是将代理配置添加到我的代码中。
gmaps = googlemaps.Client(key=googleAPIkey, requests_kwargs={'proxies':{"http":"http://<proxy server>","https":"http://<proxy_server>"})