How to skip certificate verification in poetry? - python

I'm trying to add a new package using poetry add, but it always comes with this error:
HTTPSConnectionPool(host='10.140.240.64', port=443): Max retries exceeded with url: /api/v4/projects/118/packages/pypi/files/47f05b39ebe470235b70724fb049985ea75fad6c1a5007ad3462f3d430da338b/tg_client-0.1.10-py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))
Who knows how to skip this verification?
Updated:
I try to add a package from private repository:
[[tool.poetry.source]]
name = "my_package"
url = "https://..."
secondary = true
Maybe that is why the solution poetry config certificates.my_package.cert false doesn't work.

https://python-poetry.org/docs/repositories/#certificates:
The value of certificates.< repository >.cert can be set to false if certificate verification is required to be skipped. This is useful for cases where a package source with self-signed certificates are used.
poetry config certificates.foo.cert false

I found 2 working solutions:
Use poetry version<=1.0.9 and use CURL_CA_BUNDLE="" poetry install;
Extract certificate from the repository as described here then copy-paste it in the end of file with path requests.utils.DEFAULT_CA_BUNDLE_PATH (python).

Related

Deactivate SSL verification globally in Python's requests or urllib package

I know that I can disable SSL verification in Python's request package as follows:
import requests
response = requests.put("some.host/RESTfulService/My/Endpoint/", verify=False)
The problem is that I use a package in which requests is used to make requests with it's default setting verify=True and I cannot access this keyword argument to set it to False which throws the obvious error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='some.host', port=443): Max retries exceeded with url: /RESTfulService/My/Endpoint/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))
Is there any way to deactivate SSL verification globally in requests e. g. by setting an environment variable?

How to resolve CERIFICATE_VERIFY_FAILED error in get_token for EventHubConsumerClient in python

I am trying to create a EventHubConsumerClient using TENANT_ID, CLIENT_ID, CLIENT_SECRET. Here is my sample code. However I always get a warning:
like this:
2021-09-27:16:56:39,92 WARNING [get_token_mixin.py:get_token] ClientSecretCredential.get_token failed: Authentication failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)
2021-09-27:16:56:39,98 WARNING [decorators.py:wrapper] EnvironmentCredential.get_token failed: Authentication failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)
os.environ["AZURE_TENANT_ID"] = tenantId
os.environ["AZURE_CLIENT_ID"] = client_id
os.environ["AZURE_CLIENT_SECRET"] = client_secret
credential = EnvironmentCredential()
self.client = EventHubConsumerClient(fully_qualified_namespace,
eventhub_name,
consumer_group=group,
credential=credential,
http_proxy=self.HTTP_PROXY, ssl_verify=True)
I know that my tenantId, clientId and secret are correct because I am able to do a post request and get a token. However to create a client, our solution does not return a connection_string and hence I have to do clientid authentication: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventhub/azure-eventhub/samples/sync_samples/client_identity_authentication.py
This might be caused either by server configuration or Python configuration.
If your z/OSMF was configured with self signed certificate, the python3 output error is:
certificate verify failed: self signed certificate in certificate chain
The default value for parameter verify is True. Python 3.6+ installer has its own default certificate store for verifying SSL connections. The system certificate store will not be used any more. To use default certificate store, python library certifi must be installed in advance.
You can use command "pip3 install certifi" to install it.
Python default certificate store was in cacert.pem file, you can get it by
import certifi
certifi.where()
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/certifi/cacert.pem'
For more information refer to the community blog

Python Requests '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)' [duplicate]

This question already has answers here:
Python requests SSL error - certificate verify failed
(5 answers)
"SSL: certificate_verify_failed" error when scraping https://www.thenewboston.com/
(7 answers)
Python Requests getting SSLerror
(6 answers)
Closed 1 year ago.
I've tried to execute a GET with python requests on a Website (that perfectly works when visited with Firefox or Google Chrome) but it fails with the following exception:
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)')))
the interesting thing is that if I execute the GET on an other Subdomain (of the same website) it is:
api.example.com Exception
app.example.com It Works
and BOTH are certified with the SAME ROOT CA and both works on Firefox or Google Chrome.
In particular the code is the following (a very simple request)
import requests
import json
s = requests.Session()
# execute the get
r = s.get("https://api.example.com/"
and Throws the Exception:
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)')))
Insted if I execute:
r = s.get("https://app.example.com/"
it works without any problem!
And I remark that boot are Signed and Cerfiticated by the same Root CA.
And Both works correctly if visited with Firefox or Google Chrome.
I don't know what to do...
Thanks for any hint...
p.s.
All the CAs are updated to the latest version.
And the versions of the packages are:
urllib3-1.26.6
certifi-2021.5.30

how to make python requests accept self signed certificate (with basic constraint CA = False)

im trying to do a https get via python requests to a local server and I'm getting a
"certificate verify failed: unable to get local issuer certificate" error.
The server uses a self signed certificate and it has basic constraint CA flag as False. I tried using the request's verify option as well. it resulted in same error.
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
Verification with openssl as well failed
error 20 at 0 depth lookup: unable to get local issuer certificate
error cer.pem: verification failed
However When I tried with a different self signed certificate with basic constraint CA flag as True, I'm getting a self signed certificate error and if I use the verify option in python requests, its working properly.
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056)'
Any idea why the self signed certificate with basic constraint CA flag as False is throwing a different error and how to get it accepted by requests module

Ubuntu Verifies SSL Cert, but Python does not: requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)

I am hosting a site using SSL / HTTPS, and am attempting to make a request to it from a Python 2.7 script on the server (Ubuntu 18.04).
When running the script, I get this error:
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)
However, when I run curl --verbose -X GET -I <url> on the same server, it says the certificate was verified.
I do know that the cert is in fact valid and is not a self signed cert.
Any ideas on what I can do to get python to accept that cert?
Edit: here's the code to trigger the issue. Note that I'm not including the URL as it is not accessible to the general public:
import requests
r = requests.get('https://www.example.org')
print r.status_code

Categories