2017-02-21 85 views
0

我使用下面的示例代碼連接谷歌pubsub從python腳本。我的組織使用代理連接到互聯網。你能告訴我如何在谷歌雲中配置代理設置嗎?我嘗試設置HTTP_PROXY env變量,但仍然失敗。谷歌pubsub代理設置

import json 
from oauth2client.contrib.gce import AppAssertionCredentials 
from oauth2client.service_account import ServiceAccountCredentials 
from httplib2 import Http 
from apiclient.discovery import build 

credentials =   AppAssertionCredentials('https://www.googleapis.com/auth/pubsub') 
scopes = ['https://www.googleapis.com/auth/pubsub', ' https://www.googleapis.com/auth/cloud-platform','https://www.googleapis.com/auth/monitoring', 'https://www.googleapis.com/auth/monitoring.write' ,'https://www.googleapis.com/auth/cloud-platform' , 'https://www.googleapis.com/auth/monitoring.read'] 
credentials = ServiceAccountCredentials.from_json_keyfile_name('path to json file', scopes=scopes) 
http_auth = credentials.authorize(Http()) 
pubsub1 = build('pubsub', 'v1',http=http_auth) 

回答

0

它的工作通過以下命令:

http_auth = credentials.authorize(Http(proxy_info =  httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, 'proxy url wihout  http://', 8080, proxy_user = '', proxy_pass = ''))) 

代替 http_auth = credentials.authorize(HTTP())