【发布时间】:2016-04-18 07:26:39
【问题描述】:
我构建了一个调用 Google Analytics API 的 Python 3.4 Web 应用程序。
class GA:
def __init__(self):
self.scope = ['https://www.googleapis.com/auth/analytics.readonly']
self.service_account_email = 'my_account_email'
self.key_file_location = 'my_key_location'
self.ga_id = 'my_ga_id'
def get_service(self, api_name = 'analytics', api_version = 'v3'):
f = open(self.key_file_location, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(self.service_account_email, key,scope=self.scope)
http = credentials.authorize(httplib2.Http())
service = build(api_name, api_version, http=http)
self.service = service
return (service)
ga = GA()
ga.get_service()
无需代理完美运行
但我需要在 Windows 服务器上设置它在公司代理后面运行。所以我尝试将http对象替换为:
p = httplib2.proxy_info_from_url("http://username:pwd@myproxyname:80")
http = credentials.authorize(httplib2.Http(proxy_info=p))
但它不起作用。所以我也尝试了:
os.environ['HTTP_PROXY']="http://username:pwd@myproxyname:80"
p = httplib2.proxy_info_from_environment(method='http')
http = credentials.authorize(httplib2.Http(proxy_info=p))
但它也不起作用。我检查了所有相关问题,但没有成功。我总是收到 TimeoutError:[WinError 10060]
【问题讨论】:
-
您是否验证过代理可以与其他 URL/请求一起使用?
-
确实如此。一个简单的httplib2.Http(proxy_info=p).request('google.com')
-
也不起作用。虽然请求包有效!但我需要使用 httplib2.Http() 来适应谷歌服务对象
标签: python proxy google-analytics-api google-api-python-client