【发布时间】:2016-02-03 14:15:00
【问题描述】:
我有以下 Python 代码 sn-p 以连接到 Google DFP 广告管理系统。它在 Python2 和 Python3 中运行良好。但是,当使用(Squid)代理时,它不适用于 Python3,因为在使用 Python3 googleads 库时,对 accounts.google.com 的调用会绕过代理。
所以我的问题是为什么对 accounts.google.com 的调用会绕过代理。
而且我不会明确调用accounts.google.com,这是由Google googleads 库完成的。 pip install googleads
我怀疑 googleads.oauth2 模块是罪魁祸首。这是一个代码sn-p:
from googleads import dfp
from googleads import oauth2
import httplib2
oauth2_client = None
try:
proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, <proxy.host>,<proxy.port>)
oauth2_client = (
oauth2.GoogleRefreshTokenClient(<dfp.client_id>, <dfp.client_secret>,
<dfp.refresh_token>, proxy_info=proxy_info
)
)
except Exception as e:
logger.critical("Could not init oauth client", e)
httpsProxyUrl = "http://{}:{}".format(<proxy.host>,<proxy.port>
self.dfp_client = dfp.DfpClient(oauth2_client, <dfp.application_name>,
network_code=<dfp.network_code>,
https_proxy=httpsProxyUrl, cache=None)
使用 Python2 运行时,Squid 日志显示:
1454506480.333 788 ::1 TCP_MISS/200 399986 CONNECT ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::8b - 1454506480.737 236 ::1 TCP_MISS/200 4767 连接 173.194.65.84:443 - HIER_DIRECT/173.194.65.84 - 1454506487.143 6399 ::1 TCP_MISS/200 900716 CONNECT ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::8b - 1454506492.123 1049 ::1 TCP_MISS/200 195254 连接 ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::8b - 1454506494.129 1928 ::1 TCP_MISS/200 7579 CONNECT ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::8b -
所有 ads.google.com 连接,这很好。还有一个到 173.194.65.84 的连接是 accounts.google.com,这也很好......我想,因为我需要一个 DNS 名称而不是 IP 地址。奇怪。
使用 Python3 运行时,我的防火墙注意到对 account.google.com 的访问。这不好,因为它绕过了代理。 ads.google.com 的流量仍然通过代理:
Squid 日志显示 ads.google.com 正在访问。这很好,但是 accounts.google.com 已经消失了:
1454507105.115 924 ::1 TCP_MISS/200 401298 CONNECT ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::64 - 1454507114.449 6664 ::1 TCP_MISS/200 903366 连接 ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::64 - 1454507118.952 612 ::1 TCP_MISS/200 196015 连接 ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::64 - 1454507120.411 1391 ::1 TCP_MISS/200 7909 CONNECT ads.google.com:443 - HIER_DIRECT/2a00:1450:4013:c00::64 -
【问题讨论】:
标签: python oauth double-click squid