Skip to content

PyInstaller unable to package python-certifi-win32 and causing the JIRA connection throw SSL error Certification Verify Failed

I am trying to make a connection to JIRA server using python and below is code:

from jira import JIRA
server =  'https://jira.company.com:444/'
usrnme = input("Enter UserId: ")
pwd = getpass()
jira_instance = JIRA(server = server, basic_auth=(usrnme, pwd))

When this code is run in powershell, I used to get this error:

runfile('C:/Users/desktop/JiraConnection.py', wdir='C:/Users/desktop')
WARNING:root:HTTPSConnectionPool(host='jira.company.com', port=444): Max retries exceeded with url: /rest/api/2/serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1051)'))) while doing GET https://jira.company.com:444/rest/api/2/serverInfo [{'params': None, 'headers': {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json,*.*;q=0.9', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json', 'X-Atlassian-Token': 'no-check'}}]
WARNING:root:Got ConnectionError [HTTPSConnectionPool(host='jira.company.com', port=444): Max retries exceeded with url: /rest/api/2/serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1051)')))] errno:None on GET https://jira.company.com:444/rest/api/2/serverInfo
{'response': None, 'request': <PreparedRequest [GET]>}
{'response': None, 'request': <PreparedRequest [GET]>}
WARNING:root:Got recoverable error from GET https://jira.company.com:444/rest/api/2/serverInfo, will retry [1/3] in 12.00957322719334s. Err: HTTPSConnectionPool(host='jira.company.com', port=444): Max retries exceeded with url: /rest/api/2/serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1051)')))
Traceback (most recent call last):

  File "C:\Users\desktop\JiraConnection.py", line 6, in <module>
    jira_instance = JIRA(server = server, basic_auth=(usrnme, pwd))

  File "C:\ProgramData\Anaconda3\lib\site-packages\jira\client.py", line 506, in __init__
    si = self.server_info()

  File "C:\ProgramData\Anaconda3\lib\site-packages\jira\client.py", line 2551, in server_info
    j = self._get_json("serverInfo")

  File "C:\ProgramData\Anaconda3\lib\site-packages\jira\client.py", line 3139, in _get_json
    r = self._session.get(url, params=params)

  File "C:\ProgramData\Anaconda3\lib\site-packages\jira\resilientsession.py", line 172, in get
    return self.__verb("GET", url, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\jira\resilientsession.py", line 156, in __verb
    response_or_exception, url, verb.upper(), retry_number

  File "C:\ProgramData\Anaconda3\lib\site-packages\jira\resilientsession.py", line 120, in __recoverable
    logging.debug("response.headers: %s", response.headers)

AttributeError: 'SSLError' object has no attribute 'headers'

To resolve this I installed python-certifi-win32 and everything works perfectly in powershell. Now, I want to make the code as executable and so used PyInstaller and it creates an executable but when I try to run and make a jira connection, I get the above error again. Is there a way to package this certificate verification in my code to solve the SSLError? Please help.