googleads / googleads-python-lib

The Python client library for Google's Ads APIs
Apache License 2.0
681 stars 974 forks source link

Getting ssl certificate issue after upgrading to googleads 13.0 #310

Closed chandni28p closed 6 years ago

chandni28p commented 6 years ago

I am getting below SSL certificate issue after upgrading to latest version of googleads

File "/u01/processes/env/installs/python-2.7.9/lib/python2.7/urllib2.py", line 1197, in do_open raise URLError(err) urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>

How can this be resolved?

msaniscalchi commented 6 years ago

Hello,

Thanks for the report! What version did you upgrade from/to, and have you recently changed the version of Python you use with this library? The error you're reporting is one we had seen commonly around the time we dropped support for Python versions below 2.7.9 for security reasons--earlier versions of Python did not perform SSL certificate verification, which left users on those versions vulnerable.

Of course, normally you don't need to do anything special for certificate verification to just work. We've noticed in previously reported issues that some platforms "forget" the certificate directory; in these cases, it was typically resolved with a system restart and/or reinstallation of Python. Other times, this resulted because of the user's proxy settings.

If necessary, you can specify the cafile to use in the configuration file. As a last resort for a short-term fix, you could disable certificate verification, but this is not recommended because of the aforementioned security vulnerability.

Regards, Mark

chandni28p commented 6 years ago

Hi Mark,

I have upgraded the googleads library from version 9.0 to 13.0 with Python 2.7.9. I was able to run the downloads with googleads version 9.0 but with the latest upgrade, it continues to give me SSL certificate issue.

I tried setting cafile and disabling certificate verification in yaml but it seems to give me the same issue. Also, we are no more using any proxy.

msaniscalchi commented 6 years ago

I tried setting cafile and disabling certificate verification in yaml but it seems to give me the same issue. Also, we are no more using any proxy.

That's interesting. Setting disable_certificate_validation should have allowed you to avoid this error. The structure of the googleads.yaml file has changed a bit between 9.0 and 13.0, I wonder if that's possibly related?

Would I be correct that this happens for all API calls you try to make with the library? It may be helpful if you can specify a trivial piece of code you can run that reproduces this issue for you, with the full stacktrace--it's not clear from what you've included in the OP where exactly this error originates from in the client library.

Regards, Mark

chandni28p commented 6 years ago

I am getting the issue only with the ReportService. Below is the stacktrace:

report_downloader.DownloadReportToFile(report_job_id, export_format, result_file) File "/u01/processes/dev1/pyve/dfp/lib/python2.7/site-packages/googleads/dfp.py", line 830, in DownloadReportToFile response = self.url_opener.open(report_url) File "/u01/processes/env/installs/python-2.7.9/lib/python2.7/urllib2.py", line 435, in open response = self._open(req, data) File "/u01/processes/env/installs/python-2.7.9/lib/python2.7/urllib2.py", line 453, in _open '_open', req) File "/u01/processes/env/installs/python-2.7.9/lib/python2.7/urllib2.py", line 413, in _call_chain result = func(*args) File "/u01/processes/env/installs/python-2.7.9/lib/python2.7/urllib2.py", line 1244, in https_open context=self._context) File "/u01/processes/env/installs/python-2.7.9/lib/python2.7/urllib2.py", line 1201, in do_open raise URLError(err) urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>

Doesn't seem to be an issue with googleads.yaml as it is being used in other services which do not seem to fail with the above issue.

msaniscalchi commented 6 years ago

Thanks for the update, I've attempted to verify by running run_inventory_report.py, which uses ReportService and the DataDownloader class. I haven't been able to reproduce it though, as the example consistently runs without any issues. No proxy was configured for the purpose of this test.

Under the circumstances, this sounds related to the platform or python installation. What OS and release are you using?

msaniscalchi commented 6 years ago

It has been some time since the last update, so I will now close this with the expectation that you were able to resolve this. Feel free to open if issues remain that are related to this client library.

Regards, Mark