Posts tagged with ssl

(1) In the area I am now, Google website is not visitable because of the Great Firewall. But I am using Clash for Windows and I could access and visit Google website. It works well on my browser.

(2)I am testing Google Ads API with simple function in Python like the following through Jupyter Notebook which is installed on my Windows 10 laptop:

import logging logging.basicConfig(level=logging.INFO) from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException    # Define the main function def main(client, customer_id):     ga_service = client.get_service("GoogleAdsService")     query = """         SELECT             campaign.id,             campaign.name         FROM campaign         ORDER BY campaign.id     """     # Issues a search request using streaming.     stream = ga_service.search_stream(customer_id=customer_id, query=query)     # Iterate through the results and print them     for batch in stream:         for row in batch.results:             print(                 f"Campaign with ID {row.campaign.id} and name "                 f"{row.campaign.name}"             ) # Load Google Ads client from storage # Replace "PATH/TO/YOUR/google-ads.yaml" with the actual path to your file googleads_client = GoogleAdsClient.load_from_storage(path=r"C:\Users\tomxi\google-ads.yaml", version="v15") # Get customer ID from user input (optional) # Replace with your desired method of obtaining the customer ID customer_id = "xxxxxxxxxx" # Call the main function try:     main(googleads_client, customer_id) except GoogleAdsException as ex:     print(         f'Request with ID "{ex.request_id}" failed with status '         f'"{ex.error.code().name}" and includes the following errors:'     )     for error in ex.failure.errors:         print(f'\tError with message "{error.message}".')         if error.location:             for field_path_element in error.location.field_path_elements:                 print(f"\t\tOn field: {field_path_element.field_name}")     sys.exit(1) 

(3)I got the error:

[TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by SSLError(SSLEOFError(8, '\[SSL: UNEXPECTED_EOF_WHILE_READING\] EOF occurred in violation of protocol (_ssl.c:1006)')))][1] 

(4)I guess the Google Ads API employs some route or something else which is not used or controlled by the Clash for Window on my laptop. I am not sure how to check and change it. Please help me.

Tried Option didn't work used in app.py

os.environ['PYTHONHTTPSVERIFY'] = '0' ssl._create_default_https_context = ssl._create_unverified_context 

using flask

data = report_downloader.DownloadReport( report, output, skip_report_header=False, skip_column_header=False, skip_report_summary=False, include_zero_impressions=True) 

and trying to get ACCOUNT_PERFORMANCE_REPORT working fine on local system when used tiangolo/uwsgi-nginx-flask:python3.6 as docker base image and deployed giving below error

 File "/google-analytics/helper_service/service.py", line 328, in sync_google_ads_word_data skip_report_summary=False, include_zero_impressions=True) File "/usr/local/lib/python3.6/site-packages/googleads/common.py", line 405, in Wrapper return utility_method(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/googleads/adwords.py", line 1268, in DownloadReport output, **kwargs) File "/usr/local/lib/python3.6/site-packages/googleads/adwords.py", line 1540, in _DownloadReport response = self._DownloadReportAsStream(post_body, **kwargs) File "/usr/local/lib/python3.6/site-packages/googleads/adwords.py", line 1614, in _DownloadReportAsStream response = self.url_opener.open(request) File "/usr/local/lib/python3.6/urllib/request.py", line 526, in open response = self._open(req, data) File "/usr/local/lib/python3.6/urllib/request.py", line 544, in _open '_open', req) File "/usr/local/lib/python3.6/urllib/request.py", line 504, in _call_chain result = func(*args) File "/usr/local/lib/python3.6/urllib/request.py", line 1361, in https_open context=self._context, check_hostname=self._check_hostname) File "/usr/local/lib/python3.6/urllib/request.py", line 1320, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>