Why I receive CERTIFICATE_VERIFY_FAILED from google adwords api?

12.5k views Asked by At

Why google adwords api stops on call this link:

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

With this error - should I load some certificate before and how?

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

Using Python 2.7.10.

Full source code: create_adwords_client_without_yaml.py

Full error code:

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

There are 4 answers

3
Sotiris Kiritsis On

Not sure if that's the problem here, but worth checking it.

Python 2.7.9 enabled certificate validation by default for HTTP connections.

The server you're connecting to does not have a certificate that is trusted by your client. pysphere should configure SSL appropriately for this use case.

Try making your request like:

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

I encountered this issue. I had my phone setup using the same DNS block list and it wasn't immediately apparent after I'd enabled the tool and resumed work on this particular project. I suggest scrutinizing your setup and verify that there aren't any adblockers (DNS level in my case ala NextDNS/hosted PiHole) enabled. Hours upon hours spent trying out python versions, certificates, reinstalling things. Hope this helps someone!

0
Mansoor Ul Haq On

Python uses certificates from 'system ssl certificate store' to certify https connection, if there is not any appropriate ssl cert in the store error occurs like this. Download ssl certificate (Open your https link in browser and click lock icon in address bar > More Information > View Certificate > Details > Export) and install it on your system as stated this link http://windows.microsoft.com/en-us/windows/import-export-certificates-private-keys#1TC=windows-7

0
tzp On

Try this, it helped me:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context