1

I am using python to make a get request to jira cloud rest api to get details of an issue, but getting this SSL verification failed error message, I am using this script

import requests
import json

url = "https://your-domain.atlassian.net/rest/agile/1.0/issue/{issueIdOrKey}"

headers = {
  "Accept": "application/json",
  "Authorization": "Bearer <access_token>"
}

response = requests.request(
   "GET",
   url,
   headers=headers
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

error message-

requests.exceptions.SSLError: HTTPSConnectionPool('host=your-domain.atlasian.net', port=443): Max retries exceeded with url: /rest/agile/1.0/issue/{issueIdOrKey} (caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed : self signed certificate in certificate chain (_ssl.c:992)')))

Suggest me possible ways to resolve this issue. Thank you!

  • Did you try to use the verify option ? `response = requests.request("GET",url,headers=headers, verify=False)` – RaiZy_Style Jul 04 '23 at 13:35
  • InsecureRequestWarning: Unverified request is being made to host 'my-domain.atlassian.net:443'. Adding certificate verification is strongly recommended `"error": "Failed to parse Connect session auth token"` – Devendra Yadav Jul 05 '23 at 05:38
  • Does this answer your question? [How to get Python requests to trust a self signed SSL certificate?](https://stackoverflow.com/questions/30405867/how-to-get-python-requests-to-trust-a-self-signed-ssl-certificate) – jpeg Jul 12 '23 at 08:26

5 Answers5

1

self signed certificate in certificate chain means that certificate chain validation has failed. Your script does not trust the certificate or one of its issuers. For more information see Beginning with SSL for a Platform Engineer. The answer from Tzane had most of what you need. But it looks like you also might want to know WHAT certificate to add.

So, first get the CA certificate, and any intermediate certs by running the following on a command line:

openssl s_client -connect your-name.atlassian.net:443 -showcerts

In the output there is a block that starts with Certificate chain. The output I got from Atlassian.net had only a server cert and CA cert.

There are blocks of output that start with

-----BEGIN CERTIFICATE-----

and end with

-----END CERTIFICATE-----

These blocks, including the lines I just showed, are a certificate. Copy the last certificate and create a pem file e.g. ca-root.pem. Place this in the same directory as your python file and then update your requests block to be:

verify = "ca-root.pem"

response = requests.request(
   "GET",
   url,
   headers=headers,
   verify=verify
)

Hope this helps.

----- UPDATE -----

Using the domain you provided, msci.atlassian.net, I have the CA cert provided at this time by Digital Cert.

-----BEGIN CERTIFICATE-----
MIIEvjCCA6agAwIBAgIQBtjZBNVYQ0b2ii+nVCJ+xDANBgkqhkiG9w0BAQsFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0yMTA0MTQwMDAwMDBaFw0zMTA0MTMyMzU5NTlaME8xCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxKTAnBgNVBAMTIERpZ2lDZXJ0IFRMUyBS
U0EgU0hBMjU2IDIwMjAgQ0ExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
AQEAwUuzZUdwvN1PWNvsnO3DZuUfMRNUrUpmRh8sCuxkB+Uu3Ny5CiDt3+PE0J6a
qXodgojlEVbbHp9YwlHnLDQNLtKS4VbL8Xlfs7uHyiUDe5pSQWYQYE9XE0nw6Ddn
g9/n00tnTCJRpt8OmRDtV1F0JuJ9x8piLhMbfyOIJVNvwTRYAIuE//i+p1hJInuW
raKImxW8oHzf6VGo1bDtN+I2tIJLYrVJmuzHZ9bjPvXj1hJeRPG/cUJ9WIQDgLGB
Afr5yjK7tI4nhyfFK3TUqNaX3sNk+crOU6JWvHgXjkkDKa77SU+kFbnO8lwZV21r
eacroicgE7XQPUDTITAHk+qZ9QIDAQABo4IBgjCCAX4wEgYDVR0TAQH/BAgwBgEB
/wIBADAdBgNVHQ4EFgQUt2ui6qiqhIx56rTaD5iyxZV2ufQwHwYDVR0jBBgwFoAU
A95QNVbRTLtm8KPiGxvDl7I90VUwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQG
CCsGAQUFBwMBBggrBgEFBQcDAjB2BggrBgEFBQcBAQRqMGgwJAYIKwYBBQUHMAGG
GGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBABggrBgEFBQcwAoY0aHR0cDovL2Nh
Y2VydHMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0R2xvYmFsUm9vdENBLmNydDBCBgNV
HR8EOzA5MDegNaAzhjFodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRH
bG9iYWxSb290Q0EuY3JsMD0GA1UdIAQ2MDQwCwYJYIZIAYb9bAIBMAcGBWeBDAEB
MAgGBmeBDAECATAIBgZngQwBAgIwCAYGZ4EMAQIDMA0GCSqGSIb3DQEBCwUAA4IB
AQCAMs5eC91uWg0Kr+HWhMvAjvqFcO3aXbMM9yt1QP6FCvrzMXi3cEsaiVi6gL3z
ax3pfs8LulicWdSQ0/1s/dCYbbdxglvPbQtaCdB73sRD2Cqk3p5BJl+7j5nL3a7h
qG+fh/50tx8bIKuxT8b1Z11dmzzp/2n3YWzW2fP9NsarA4h20ksudYbj/NhVfSbC
EXffPgK2fPOre3qGNm+499iTcc+G33Mw+nur7SpZyEKEOxEXGlLzyQ4UfaJbcme6
ce1XR2bFuAJKZTRei9AqPCCcUZlM51Ke92sRKw2Sfh3oius2FkOH6ipjv3U/697E
A7sKPPcw7+uvTPyLNhBzPvOk
-----END CERTIFICATE-----
0

We had a similar cert issue with another web API that came up randomly on some machines. What we ended up doing is getting the ISRG Root X1 from Let's Encrypt and passing it manually to the request

verify = "isrgrootx1.pem"

response = requests.request(
   "GET",
   url,
   headers=headers,
   verify=verify
)
Tzane
  • 2,752
  • 1
  • 10
  • 21
0

Getting certificate issues like that (self signed certificate in chain) from such a public website smells like you're behind a corporate proxy. Is that the case?

You can simply check that if you connect to the internet from your home, or hotspot, without being behind proxy. If it works - then that's your problem.

You can also debug it further running curl -v <URL>. It will display some additional cert information.

To solve it, you need to trust your company CA certificate so certificates signed by this root CA are trusted. Here's a to do it on Ubuntu


Importing a company certificate is something usually the IT department helps with. The process is different between OS's, but in general (and I'll give a Linux example below) this is how it goes:

  1. You need to get the root CA certificate. This is a certificate the company signs certificate with. Your IT will probably have it, or the knowledge where you can get it from. This is a file with .crt suffix
  2. You put this file in designated location, depending on your OS. For Ubuntu this would be /usr/local/share/ca-certificates
  3. Run sudo update-ca-certificates to update OS certificates

If you're running inside Docker, the process is the same and again, it might be different depending on the OS type.

Chen A.
  • 10,140
  • 3
  • 42
  • 61
  • Yes I am behind a proxy. I tried the `curl -v ` and getting this `Connected to my-domain.atlassian.net (104.192.142.18) port 443 ALPN, offering h2 successfully set certificate verify locations: CAfile: /path/to/ca/certificate * TLSv1.3 (OUT), TLS handshake, Client hello (1): OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to my-domain.atlassian.net:443 curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to my-domain.atlassian.net:443` – Devendra Yadav Jul 03 '23 at 08:08
  • Does it work if you ignore certificates? (try curl -k) – Chen A. Jul 03 '23 at 10:51
  • No this time it is showing `curl: (35) openSSL SSL_connect: SSL_ERROR_SYSCALL in connection to my-domain.atlassian.net:443` – Devendra Yadav Jul 05 '23 at 05:34
  • This also may indicate some sort of certificate problem. You need to import your company certificate on that host / docker container. – Chen A. Jul 05 '23 at 05:47
  • Can you tell me the whole process how to do it? – Devendra Yadav Jul 07 '23 at 06:01
  • @DevendraYadav I've updated the answer with an explanation – Chen A. Jul 07 '23 at 10:21
0

Are you using YOUR domain name in the request?

From the errors, it looks like you're trying to use the fictitious domains my-domain.atlassian.net and your-domain.atlassian.net in your request.

David Bakkers
  • 453
  • 3
  • 13
0
  1. Try doing ping <your-domain>.atlassian.net and ensuring it can get through
  2. If you're on VPN try turning it off because VPN can do self-signed certs that cause all kinds of issues
  3. Otherwise check out your env variables which are used by python...attaching a short script we've used when dealing with these issues
if [ -w /etc/ssl/certs ]
then
    CERT_PATH=/etc/ssl/certs/certs.pem
else
    CERT_PATH=~/.certs.pem
fi
security export -t certs -f pemseq -k login.keychain-db -o $CERT_PATH
echo "\nexport REQUESTS_CA_BUNDLE=$CERT_PATH" >> ~/.bash_profile
echo "\nexport REQUESTS_CA_BUNDLE=$CERT_PATH" >> ~/.zshrc
smoot
  • 21
  • 5