Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

The dreaded CERTIFICATE_VERIFY_FAILED with Python Bitbucket API

Rob Lamb June 23, 2022

Hi all,

I'm trying to connect to our internal Bitbucket server via the Atlassian Python API, using a token:

from atlassian import Bitbucket

bb = Bitbucket(url='https://<ourURL>',token = '<myToken>')
data = bb.project_list()
for i in data:
    print(i)

 

When I run the above code I get the error "SSL: CERTIFICATE_VERIFY_FAILED".

I'm running on a Mac, using IDLE.  

I've tried adding a "verify=False" to the connection string, but then I get an error that the parameter "verify" isn't recognized.

I'm new to using APIs (and certificates) so I'm probably missing something basic here.  Any ideas?

Thanks!

 

5 answers

1 accepted

0 votes
Answer accepted
Rob Lamb June 29, 2022

I was able to get this to work following these steps:

Specify the certificate store per:

https://stackoverflow.com/questions/40684543/how-to-make-python-use-ca-certificates-from-mac-os-truststore

This included:
1) Installed “certifi”
2) Added this to my .bash_profile:
CERT_PATH=$(python3.8 -m certifi)
export SSL_CERT_FILE=${CERT_PATH}
export REQUESTS_CA_BUNDLE=${CERT_PATH}

3) Linked “ln -s” the cacert.pem file to the cert.pem file

 

Then I re-added the internal Certs for our repos to the cacert.pem file

0 votes
Ellite Hanry
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 13, 2025

Yes, it is great that you can solve the issue, but if in the future you face the error issue, you can refer to the following guide:- https://cheapsslweb.com/blog/ssl-certificate-verify-failed-error-in-python/.

I hope it helps!

0 votes
Ellite Hanry
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 13, 2025

The error occurs while running the code on a Mac and still getting the "SSL: CERTIFICATE_VERIFY_FAILED." It can occur when making HTTPS requests using the requests module in Python. I can refer to the following helpful guide: https://cheapsslweb.com/blog/ssl-certificate-verify-failed-error-in-python/. Maybe it will help to solve the error.

0 votes
Zaheer Kazi January 15, 2024

i tried downgrading the urllib3 to 1.24.1 and it worked for me

0 votes
Florian Bonniec
Community Champion
June 23, 2022

Hi

 

Have you try  verify_ssl=False ?

 

Bitbucket(url='https://<ourURL>',token = '<myToken>', verify_ssl=False)

Rob Lamb June 24, 2022

Hi Florian, 

This is much closer!  Now I get a string of 30 warnings:

"InsecureRequestWarning: Unverified HTTPS request is being made to host...Adding certificate verification is strongly advised."

These are followed by:

"requests.exceptions.TooManyRedirects: Exceeded 30 redirects.".

Is there a way to disable warnings?  

And how did you find the verify_ssl parameter?  Is there documentation somewhere that I missed?

Thanks so much for the help!

--Rob

Florian Bonniec
Community Champion
June 24, 2022

Hi

 

I found the param to use in the code of the library you are using.

 

https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/rest_client.py#L45

 

Documentation is here also

https://pypi.org/project/atlassian-python-api/

Rob Lamb June 24, 2022

Aha, thanks for that!  Unfortunately I don't see a way to disable the warnings to get this to work with the verify_ssl=False flag. 

I've tried multiple solutions to the SSL certificate problem (such as running "Install Certificates.command"),  but so far nothing has worked.

Florian Bonniec
Community Champion
June 27, 2022

Usually it's ok to have warning, the "requests.exceptions.TooManyRedirects: Exceeded 30 redirects." is another error.

 

Can you try to add an header to your request following this recommandation

https://stackoverflow.com/questions/23651947/python-requests-requests-exceptions-toomanyredirects-exceeded-30-redirects

Rob Lamb June 29, 2022

Thank you for the help!  I eventually got it to work, details in the next post.

Christian B. February 3, 2023

how?

Rob Lamb February 3, 2023

Hi Christian, please see the "Answer Accepted" post from me at the top of this thread for details.

Christian B. February 3, 2023

oh, sorry.

Many Thanks!

Suggest an answer

Log in or Sign up to answer