Forums

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

Python script to Jira failed with "Err: 401"

John_Dumbar June 19, 2020

Python: 3.8
Jira module: jira-2.0.0-py2.py3-none-any.whl

This is my python script:

import jira.client
from jira import JIRA
import getpass
import urllib3
urllib3.disable_warnings()

passwd = getpass.getpass("Password: ")
jira = JIRA(options = {'server': 'https://jira.example.com', 'verify': False}, basic_auth=('username', passwd))

Output:

WARNING:root:Got recoverable error from GET https://jira.example.com/rest/api/2/serverInfo, will retry [1/3] in 13.933683721316022s. Err: 401

The point is, authentication to Jira page is with:
* username
* password

I don't have neither a ca.cert nor a rsa_id file nor any similar thing stored into my computer to be able to access jira page through a web browser.

 

Any idea to implement this kind of authentication into my python script?

 

2 answers

0 votes
Moses Thomas
Community Champion
June 22, 2020

.

0 votes
Moses Thomas
Community Champion
June 20, 2020

@John_Dumbar   401 response indicates that authorization has been refused for those credentials.  You will need to make  sure that the  user credentials are correct  besides some thing is wrong with your code. Visit the official doc  here on how to  do it  https://jira.readthedocs.io/en/master/examples.html#authentication

Kind regards,

Mo

John_Dumbar June 22, 2020

Hi @Moses Thomas,

The page that you show is sadly not enough explicit, and that's why I came here to ask.

My login is using my email as username and my email passwd. I login to Jira page every single day with that credentials, and I well know this data. That's why I think a wrong username/passwd is not a candidate to be the issue. The "method" to send my login request and credentials, is my first suspect, but obviously I'm open to know that there is other posible cause. That's why I decided to come here to ask for help from the experts in jira module.

And I have to say that I'm not an expert programmer.

Let's make a review (I include only a few words from the error message because I think there is a limit in the number of characters here):

1) My first try was according to the page. Supposedly this syntax must use the Jira page cookie that already exist from my recent login to jira page, but it raises the ssl certificate issue. I do not have a file with a certificate stored in my computer. If it exist it was not installed by me and I don't know where to look for it.

import jira.client
from jira import JIRA
import getpass
import urllib3
urllib3.disable_warnings()

jac = JIRA('https://jira.example.com')
auth_Jira = JIRA(auth=('username', 'password'))

Error:

WARNING:root:HTTPSConnectionPool(host='jira.example.com', port=443): 

unable to get local issuer certificate (_ssl.c:1108)')))

 

2) Changing the line where the jira server is specified, adding the 'verify': False, and adding the urllib3 lines, changes the issue. Now the jira server is not recognized correctly. I think the ssl certificate issue is not there just because the script does not really hit the jira page.

jac = JIRA(options={'server': 'https://jira.example.com:443', 'verify': False})
auth_Jira = JIRA(auth=('username', 'password'))

Error:

WARNING:root:HTTPConnectionPool(host='localhost', port=2990): 
[WinError 10061]

 

3) Separating the line where I specify the jira server and the option 'verify': False, makes that jira server is recognized again, but ssl certificate issue is back again.

jac = JIRA('https://jira.example.com')
jas = JIRA(options={'verify': False})
auth_Jira = JIRA(auth=('username', 'password'))

Error:

WARNING:root:HTTPSConnectionPool(host='jira.example.com', port=443): unable to get local issuer certificate (_ssl.c:1108)'))) 

 

4) As the examples on the page were not successfull, I opened my search to other pages. This try shows not ssl, not authorization issue, but a super long list of python issues. So long that it was not possible to copy it complet here. In this try, the errors delay a couple of minutes to appear.

jira = JIRA(options={'server': 'https://jira.example.com', 'verify': False}, auth=('username', 'password'))

Error:

Traceback (most recent call last):
File "C:\Users\uvazquez\AppData\Local\Programs\Python\Python38\lib\encodings\idna.py", line 149, in encode
if errors != 'strict':
RecursionError: maximum recursion depth exceeded in comparison

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "web-test-1.0.py", line 9, in <module>
jira = JIRA(options={'server': 'https://jira.example.com', 'verify': False}, auth=('username', 'password'))

 

5) This is the last, that seems to be only a matter of authorization.

jira = JIRA(options={'server': 'https://jira.example.com', 'verify': False}, basic_auth=('username', 'password'))

Error:

WARNING:root:Got recoverable error from GET https://jira.example.com/rest/api/2/serverInfo, will retry [1/3] in 11.002050637141101s. Err: 401

 

What am I missing?

Moses Thomas
Community Champion
June 22, 2020

@John_Dumbar   There are  two  different things here Jira cloud  is different from Jira  server  self hosted.  I think you are using JIRA cloud.

For the JIRA cloud, Standard basic authentication is now deprecated in JIRA from June 2019.

An API key is required for basic authentication which now replaces the 'password' requirement. API key's can be generated from:

API tokens   After generating the token, now your code will look like this

from jira import JIRA

options = {'server': 'https://jira.example.com'}
JIRA(options=options, basic_auth=('myemail@email.com', 'myApiToken')

 

Try and give feed back.

Kind regards,

Moses

John_Dumbar June 22, 2020

Hi @Moses Thomas ,

The syntax exactly as you put it, returns the ssl certificate issue.

Adding the verification = false:

from jira import JIRA

options = {'server': 'https://jira.example.com', 'verify': False}
JIRA(options=options, basic_auth=('myemail@email.com', 'myApiToken')

It returns the 401 error.

 

In addition to that, I have asked several people and everybody think that it is stored into an internal server. Even though nobody knows the jira admin team (this is a too big company and it's impossible to know every single people/team).

Moses Thomas
Community Champion
June 22, 2020

@John_Dumbar 

  1. @John_Dumbar have you generated the token? If yes substitute the token string and enter the right URl to access JIRA. Remove the "verify:false"  it should work for Jira cloud
  2. If you have on-premise; then without the "verify:false" ;  use basic_auth=('login','password')
John_Dumbar June 22, 2020

Hi @Moses Thomas , I generated the token and used it as a passwd.

I tried that combination without 'verify' and with 'basic_auth', several times before and I did it again. This is the complete error messages:

WARNINGrootHTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)'))) while doing GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo [{'params' None, 'headers' {'User-Agent' 'python-requests2.24.0', 'Accept-Encoding' 'gzip, deflate', 'Accept' 'applicationjson,.;q=0.9', 'Connection' 'keep-alive', 'Cache-Control' 'no-cache', 'Content-Type' 'applicationjson', 'X-Atlassian-Token' 'no-check'}}]
WARNINGrootGot ConnectionError [HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))] errnoNone on GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo
{'response' None, 'request' PreparedRequest [GET]}{'response' None, 'request' PreparedRequest [GET]}
WARNINGrootGot recoverable error from GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo, will retry [13] in 15.687256507829177s. Err HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))
WARNINGrootHTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)'))) while doing GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo [{'params' None, 'headers' {'User-Agent' 'python-requests2.24.0', 'Accept-Encoding' 'gzip, deflate', 'Accept' 'applicationjson,.;q=0.9', 'Connection' 'keep-alive', 'Cache-Control' 'no-cache', 'Content-Type' 'applicationjson', 'X-Atlassian-Token' 'no-check'}}]
WARNINGrootGot ConnectionError [HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))] errnoNone on GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo
{'response' None, 'request' PreparedRequest [GET]}{'response' None, 'request' PreparedRequest [GET]}
WARNINGrootGot recoverable error from GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo, will retry [23] in 30.255299296396228s. Err HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))
WARNINGrootHTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)'))) while doing GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo [{'params' None, 'headers' {'User-Agent' 'python-requests2.24.0', 'Accept-Encoding' 'gzip, deflate', 'Accept' 'applicationjson,.;q=0.9', 'Connection' 'keep-alive', 'Cache-Control' 'no-cache', 'Content-Type' 'applicationjson', 'X-Atlassian-Token' 'no-check'}}]
WARNINGrootGot ConnectionError [HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))] errnoNone on GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo
{'response' None, 'request' PreparedRequest [GET]}{'response' None, 'request' PreparedRequest [GET]}
WARNINGrootGot recoverable error from GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo, will retry [33] in 18.771131816055416s. Err HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))
WARNINGrootHTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)'))) while doing GET httpsjira-sd.mc1.oracleiaas.comrestapi2serverInfo [{'params' None, 'headers' {'User-Agent' 'python-requests2.24.0', 'Accept-Encoding' 'gzip, deflate', 'Accept' 'applicationjson,.;q=0.9', 'Connection' 'keep-alive', 'Cache-Control' 'no-cache', 'Content-Type' 'applicationjson', 'X-Atlassian-Token' 'no-check'}}]
Traceback (most recent call last)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py, line 670, in urlopen
httplib_response = self._make_request(
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py, line 381, in _make_request
self._validate_conn(conn)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py, line 976, in _validate_conn
conn.connect()
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3connection.py, line 361, in connect
self.sock = ssl_wrap_socket(
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilssl_.py, line 377, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libssl.py, line 500, in wrap_socket
return self.sslsocket_class._create(
File CUsersuvazquezAppDataLocalProgramsPythonPython38libssl.py, line 1040, in _create
self.do_handshake()
File CUsersuvazquezAppDataLocalProgramsPythonPython38libssl.py, line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError [SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)

During handling of the above exception, another exception occurred

Traceback (most recent call last)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.py, line 439, in send
resp = conn.urlopen(
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3connectionpool.py, line 724, in urlopen
retries = retries.increment(
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesurllib3utilretry.py, line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))

During handling of the above exception, another exception occurred

Traceback (most recent call last)
File web-test-1.0.py, line 9, in module
JIRA(options = options, basic_auth = ('ulises.vazquez@oracle.com', 'YesperoABC23'))
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesjiraclient.py, line 472, in __init__
si = self.server_info()
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesjiraclient.py, line 2133, in server_info
j = self._get_json('serverInfo')
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesjiraclient.py, line 2549, in _get_json
r = self._session.get(url, params=params)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesjiraresilientsession.py, line 151, in get
return self.__verb('GET', url, kwargs)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesjiraresilientsession.py, line 146, in __verb
raise exception
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesjiraresilientsession.py, line 125, in __verb
response = method(url, timeout=self.timeout, kwargs)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py, line 543, in get
return self.request('GET', url, kwargs)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py, line 530, in request
resp = self.send(prep, send_kwargs)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesrequestssessions.py, line 643, in send
r = adapter.send(request, kwargs)
File CUsersuvazquezAppDataLocalProgramsPythonPython38libsite-packagesrequestsadapters.py, line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError HTTPSConnectionPool(host='jira-sd.mc1.oracleiaas.com', port=443) Max retries exceeded with url restapi2serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL CERTIFICATE_VERIFY_FAILED] certificate verify failed unable to get local issuer certificate (_ssl.c1108)')))

 

Moses Thomas
Community Champion
June 22, 2020

@John_Dumbar  

it seems that your are using the packages  url lib3    

run this command  and try again

  1. pip install --upgrade certifi
John_Dumbar June 22, 2020

@Moses Thomas 

I was updated the certifi module prior to come to this place, but there is a new recently released version and I updated it.

C:\>python -m pip install --upgrade d:\Downloads\certifi-2020.6.20-py2.py3-none-any.whl
Processing d:\downloads\certifi-2020.6.20-py2.py3-none-any.whl
Installing collected packages: certifi
Attempting uninstall: certifi
Found existing installation: certifi 2020.4.5.2
Uninstalling certifi-2020.4.5.2:
Successfully uninstalled certifi-2020.4.5.2
Successfully installed certifi-2020.6.20

There was no change in the behavior of the script. Without the 'verify' it returns the ssl certificate issue. With the 'verify', it returns the 401 issue.

 

This is crazy.

Moses Thomas
Community Champion
June 22, 2020

@John_Dumbar Windows you are using, please restart your Work station/Computer. If it doesn't work then its Weird.

John_Dumbar June 24, 2020

Hi @Moses Thomas

After I rebooted my computer this is the result:

options = {'server': 'https://jira.example.com'}
JIRA(options = options, auth = ('username', 'passwd'))

This returns the ssl certificate issue.


********************************************

options = {'server': 'https://jira.example.com', 'verify': False}
JIRA(options = options, auth = ('MyUser', 'MyPasswd'))

This returns a VERY long list of "python" errors. This is just like 1% of the long list.

Traceback (most recent call last):
File "C:\Users\uvazquez\AppData\Local\Programs\Python\Python38\lib\encodings\idna.py", line 149, in encode
if errors != 'strict':
RecursionError: maximum recursion depth exceeded in comparison

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "web-test-1.0.py", line 10, in <module>
JIRA(options = options, auth = ('MyUser', 'MyPasswd'))
File "C:\Users\uvazquez\AppData\Local\Programs\Python\Python38\lib\site-packages\jira\client.py", line 462, in __init__
user = self.session(auth)
File "C:\Users\uvazquez\AppData\Local\Programs\Python\Python38\lib\site-packages\jira\client.py", line 2446, in session
r = self._session.post(url, data=json.dumps(authentication_data))
File "C:\Users\uvazquez\AppData\Local\Programs\Python\Python38\lib\site-packages\jira\resilientsession.py", line 154, in post
return self.__verb('POST', url, **kwargs) 

Suggest an answer

Log in or Sign up to answer