criteo / criteo-api-python-sdk

4 stars 3 forks source link

SSLError: bad handshake, certificate verify failed #11

Closed ajendrex closed 1 year ago

ajendrex commented 1 year ago

Hello,

I'm migrating from criteo-marketing-transition to criteo-api-marketingsolutions-sdk. While the credentials that I'm using work with the former library, I receive the following traceback error on the new one:

  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/api_client.py", line 771, in __call__
    return self.callable(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/api/audience_api.py", line 347, in __get_audiences
    return self.call_with_http_info(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/api_client.py", line 849, in call_with_http_info
    collection_formats=params['collection_format'])
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/api_client.py", line 414, in call_api
    _check_type)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/api_client.py", line 199, in __call_api
    _request_timeout=_request_timeout)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/api_client.py", line 438, in request
    headers=headers)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/rest.py", line 238, in GET
    query_params=query_params)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/rest.py", line 143, in request
    access_token = self.refresh_token(headers)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/rest.py", line 308, in refresh_token
    self.token = self.call_auth_endpoint(headers)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/rest.py", line 329, in call_auth_endpoint
    body=None)
  File "/usr/local/lib/python3.7/site-packages/criteo_api_marketingsolutions_v2022_10/rest.py", line 180, in request
    headers=headers)
  File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 80, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 171, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 336, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 767, in urlopen
    **response_kw
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 767, in urlopen
    **response_kw
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 767, in urlopen
    **response_kw
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.criteo.com', port=443): Max retries exceeded with url: /oauth2/token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

This is the code that I'm trying out:

    def test_criteo(self, username: str, password: str):
        from criteo_api_marketingsolutions_v2022_10 import Configuration, ApiClient
        from criteo_api_marketingsolutions_v2022_10.api.audience_api import AudienceApi

        configuration = Configuration(username=username, password=password)
        client = ApiClient(configuration)
        api = AudienceApi(client)

        print(api.get_audiences())

Any help would be very appreciated, thank you!

ajendrex commented 1 year ago

I think I found the problem. I upgraded urllib3 to the latest version and now it works.