2

I'm writing some script to download attachments from JIRA issues. As a proof-of-concept, I went through the JIRA API using cURL (on a windows machine through Cygwin 64 bit) and was able to authenticate and retrieve full representation of an issue (in JSON format) with the following cURL command:

curl -u username:password -k -X GET https://jira.localhost.com/jira/rest/api/2/issue/{issuekey}

HOWEVER, once I started scripting in python (using the requests module) the same request would no longer go through

import requests
from requests.auth import HTTPBasicAuth

r = requests.get("https://jira.wgt.com/jira/rest/api/2/issue/{issueKey}", auth = HTTPBasicAuth(username, password), verify = False)
print response.status_code
print response.text

which prints:

404

{"errorMessages":["Issue Does Not Exist"],"errors":{}}

Using Charles I was also able to see that the server had returned a 301 error (possibly from redirecting https to http?). Maybe requests wasn't able to handle the redirect properly? Any input on how to handle this would be great

1
  • If there are redirects involved it is very likely (if you're on requests 2.3.0) that we're stripping the authentication automatically for your security. You should check response.history and if there are responses there, check their request headers. Similarly you can check this response's headers and look for 'Authorization'. In all likelihood it's in a request's header dictionary from one of the redirects, but not in the request that was sent for the final response. Commented Jul 4, 2014 at 20:39

1 Answer 1

5

For me next code works perfectly fine :

import requests
url = "http://localhost:8080/jira/rest/api/2/issue/TEST-1"
r = requests.get(url, auth=("admin", "admin"))
print r.status_code
print r.json()

Hope that will solve your problem as well. Also, check your JIRA setup - when you install JIRA, you specify your home page. In my case it was http://localhost:8080/jira and when i tried to use some Attlassian examples and use http://localhost:8080/rest/api/v2/issue/issue it didn't work for me either. This base_url is specified in your JIRA properties file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.