I am trying to connect to Jira REST API running behind apache proxy. I tried to use python-jira module for this task and it worked fine as far as I was connecting to Jira directly, bypassing apache proxy authorization. However, with apache proxy up I am steadily getting "Err: 401 Unauthorized" error.
the problem is that I need to provide authorization credentials twice, one for proxy and one for Jira.
All tests had been done on my local VM.
- apache proxy is running on standard port 80 and redirects 127.0.0.1/jira to 127.0.0.1:8080/jira
- jira us running on port 8080
Here is the working curl command where:
- jirauser - jira user to use for authorization jirapass
- jirapassword to use for authorization
- dGVzdDp3d3c= - is base64 encoded proxyuser:proxypass string
it is actually running and producing results
curl -u 'jirauser:jirapass' -X GET -H "Authorization: Basic dGVzdDp3d3c=" -H "Content-Type: application/json" "http://127.0.0.1/jira/rest/api/2/search?jql=key=DEV4"
for the python-jira module I think that I need to tweak 'options' parameter to add to 'headers' list the "Authorization: Basic dGVzdDp3d3c=" but somehow it doesn't work.
from jira import JIRA, JIRAError
import sys
username="Jira_username"
password="Jira_password"
jira_options = {
'server': 'http://127.0.0.1/jira',
'verify': True,
'headers' : {
'X-Atlassian-Token': 'no-check',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Authorization': 'Token token="dGVzdDp3d3c\="'
}
}
try:
jira = JIRA(
options = jira_options,
basic_auth = (username,password),
validate = True,
)
except JIRAError as e:
print("Failed in Jira connection initialisation with error [%s]" % e)
sys.exit()
I also tried to do a direct call with requests librarty
r = requests.get('http://127.0.0.1/jira/rest/api/2/search?jql=key=DEV4',auth=('jirauser','jirapass'),headers={'Content-Type': 'application/json','Authorization': "Basic %s" % "dGVzdDp3d3c="})
but the result again was: 401 Error
I am getting really confused on why curl command works but python code fails what is wrong here? (since curl is working I assume this is not an issue in environment setup)