为什么我从google adwords api收到CERTIFICATE_VERIFY_FAILED?

时间:2015-06-08 08:55:45

标签: python-2.7 google-api google-adwords google-api-client google-api-python-client

为什么google adwords api会在此链接中停止:

https://adwords.google.com/api/adwords/mcm/v201502/CustomerService?wsdl

出现此错误 - 我应该在之前和之后加载一些证书吗?

urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>

使用Python 2.7.10。

完整源代码: create_adwords_client_without_yaml.py

完整错误代码:

Traceback (most recent call last):
  File "C:/Users/Crezary Wagner/PycharmProjects/learn-adwords/src/examples/create_adwords_client_without_yaml.py", line 56, in <module>
    CLIENT_CUSTOMER_ID)
  File "C:/Users/Crezary Wagner/PycharmProjects/learn-adwords/src/examples/create_adwords_client_without_yaml.py", line 50, in main
    customer = adwords_client.GetService('CustomerService').get()
  File "C:\root\Python27\lib\site-packages\googleads\adwords.py", line 256, in GetService
    proxy=proxy_option, cache=self.cache, timeout=3600)
  File "C:\root\Python27\lib\site-packages\suds\client.py", line 115, in __init__
    self.wsdl = reader.open(url)
  File "C:\root\Python27\lib\site-packages\suds\reader.py", line 150, in open
    d = self.fn(url, self.options)
  File "C:\root\Python27\lib\site-packages\suds\wsdl.py", line 136, in __init__
    d = reader.open(url)
  File "C:\root\Python27\lib\site-packages\suds\reader.py", line 74, in open
    d = self.download(url)
  File "C:\root\Python27\lib\site-packages\suds\reader.py", line 92, in download
    fp = self.options.transport.open(Request(url))
  File "C:\root\Python27\lib\site-packages\suds\transport\https.py", line 62, in open
    return HttpTransport.open(self, request)
  File "C:\root\Python27\lib\site-packages\suds\transport\http.py", line 67, in open
    return self.u2open(u2request)
  File "C:\root\Python27\lib\site-packages\suds\transport\http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "C:\root\Python27\lib\urllib2.py", line 431, in open
    response = self._open(req, data)
  File "C:\root\Python27\lib\urllib2.py", line 449, in _open
    '_open', req)
  File "C:\root\Python27\lib\urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "C:\root\Python27\lib\urllib2.py", line 1240, in https_open
    context=self._context)
  File "C:\root\Python27\lib\urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>

4 个答案:

答案 0 :(得分:3)

Python使用来自&#39; system ssl证书库的证书&#39;验证https连接,如果存储中没有任何适当的ssl证书,则会发生这样的错误。 下载ssl证书(在浏览器中打开您的https链接,然后点击地址栏中的锁定图标&gt;更多信息&gt;查看证书&gt;详细信息&gt;导出)并按照此链接http://windows.microsoft.com/en-us/windows/import-export-certificates-private-keys#1TC=windows-7

答案 1 :(得分:2)

不确定这是否是问题,但值得检查。

Python 2.7.9默认情况下为HTTP个连接启用了证书验证。

您要连接的服务器没有您的客户端信任的证书。 pysphere应该为此用例适当地配置SSL

尝试提出以下请求:

requests.get('https://adwords.google.com/api/adwords/mcm/v201502/CustomerService?wsdl', verify=False)

答案 2 :(得分:0)

试试这个,它帮助了我:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

答案 3 :(得分:0)

我遇到了这个问题。我的电话设置使用了相同的DNS阻止列表,在启用该工具并恢复该特定项目的工作后,这种设置并没有立即显现出来。我建议仔细检查您的设置,并确认没有启用任何广告拦截器(在我的情况下为DNS级别,例如NextDNS /托管的PiHole)。数小时花在尝试python版本,证书,重新安装上。希望这对某人有帮助!