My ultimate goal is to have a program automatically download a JSON output from a JIRA bug repository, via the JIRA API. I have experience in python but almost none in RESTful API development. Currently trying to follow directions located here: https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication, and I cannot seem to get past Step 1, where at first, it seems simple to do:
Step 1. Create a new session using the JIRA REST API
We need to get a session cookie from JIRA, so the first thing we need to do is create a new session using the <a class="external-link" href="https://docs.atlassian.com/jira/REST/latest/#auth/1/session" rel="nofollow noopener noreferrer">session</a> resource in the JIRA REST API.
Tip: You can also use the session resource to get information about the currently authenticated user in the current session (GET), or log the current user out of JIRA (DELETE).
To do this, just POST the desired user credentials (as JSON) to the session resource:
| Example resource | <span class="nolink"><a href="http://jira.example.com:8090/jira/rest/auth/1/session" rel="nofollow noopener noreferrer">http://jira.example.com:8090/jira/rest/auth/1/session</a></span> |
|---|
| Example credentials | { "username": "myuser", "password": "mypassword" } |
|---|
This will create a new session and return the requested session information, which will look similar to the following:
{
"session":
{
"name":"JSESSIONID",
"value":"6E3487971234567896704A9EB4AE501F"
},
"loginInfo":
{
"failedLoginCount":1,
"loginCount":2,
"lastFailedLoginTime":"2013-11-27T09:43:28.839+0000",
"previousLoginTime":"2013-12-04T07:54:59.824+0000"
}
}More importantly, you will get the session cookie (in the header of the response) from the server, which you can use in subsequent requests. You can see an example of this below. You'll notice that the cookie name and value are the same as the cookie name and value in the session response above.
Set-Cookie: JSESSIONID=6E3487971234567896704A9EB4AE501F; Path=/; HttpOnly
Since use of 'requests' library is recommended everywhere in help forums I've seen attempting to help people who are new to RESTful development because it's the simplest to use, I attempted to create a new session in my python 2.7 program in the following way, using the above tutorial info, plus info from the 'requests' libary tutorial site, http://docs.python-requests.org/en/master/user/quickstart/#make-a-request :
jirainterface.py:
import requests
loginurl = 'https://jira01.devtools.mycompany.com/rest/auth/1/session'
resp = requests.post(loginurl, data={'username': 'myusername','password': 'mypassword'})
print(resp.status_code, resp.reason)
Error Response:
Traceback (most recent call last):
File "jiraIinterface.py", line 21, in <module>
resp = requests.post(loginurl, data={'username': 'myusername','password': 'mypassword'})
File "C:\Python27\lib\site-packages\requests\api.py", line 110, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 497, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
There is nothing wrong with the loginurl, if I type it in to a browser, I get a response very much like the above sample requested session info.
Any help or insight is appreciated.