user3803502
user3803502

Reputation:

Can access JIRA API with cURL but not Requests

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

Upvotes: 2

Views: 6295

Answers (1)

Andrew Zakordonetes
Andrew Zakordonetes

Reputation: 129

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.

Upvotes: 5

Related Questions