Unable to connect to JIRA from python using REST API
Error Message - You are not authenticated. Authentication required to perform this operation
Python code :
import json
import requests
import urllib3
urllib3.disable_warnings()
url = 'https://domainname.atlassian.net/rest/api/3/project'
data = {"key": "sangi","description": "Project_Monday","name": "learn_jira_sangi","projectTypeKey": "software","leadAccountId" : "5c7cb96ee6##########"}
data_json = json.dumps(data)
headers = {'Bearer': 'CfZP25G############', 'Content-Type':'application/json','Accept':'application/json'}
response = requests.post(url, data=data_json, headers=headers , verify=False)
resp=response.json()
print(resp)
I don't use Python, I use C#, and I still use base64 encoded username and password, but ...
The format I use seems different, I have
newRequest.Headers.Add("Authorization", "Basic " + base64Credentials)
and for the Tempo API, where I do use a bearer token, the format is
newRequest.Headers.Add("Authorization", "Bearer " + "xxxxxxxxxx")
So the point I'm making is that both mine start with the word Authorization which you don't have - try to add it in.
P.S. You should remove (mask) your bearer token and company URL - other people could get use those details
I have tried in this way -
headers = {'Authorization': 'Bearer = CfZP25GHMajE356', 'Content-Type':'application/json','Accept':'application/json'}
Also in this way -
headers = {'Authorization': 'Bearer' + 'CfZP25GHajE356', 'Content-Type':'application/json','Accept':'application/json'}
Also in this way -
headers = {'Authorization', 'Bearer' + 'CfZP25GH9E356', 'Content-Type':'application/json','Accept':'application/json'}
Nothing worked!
Getting same error - {'errorMessages': ['You are not authenticated. Authentication required to perform this operation.'], 'errors': {}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You may still want to try base64 encoding your username and password - this StackOverflow answer shows a Python implementation
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The link provided here is also not giving the solution.. Can you help me out with any other option?
Stuck in this for more than a day!:(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Possibly post your question on the Developer Community, it's a more technical group and someone there may use Python
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've been looking into the use of an API token for Jira and it's different to what Tempo use, so what I was asking you earlier to try is nonsense.
This page describes how to use the Jira token and they say you can just replace your password with the token. I've tried that, still using the base64 encoding, and it works. So the format would be
newRequest.Headers.Add("Authorization", "Basic " + base64Credentials)
where the base64Credentials is created using my username (which is e-mail address) and the generated token.
For completeness, in C# the encoded credentials routine looks like this
string mergedCredentials = string.Format("{0}:{1}", m_Username, m_token);
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);
Hopefully you already have a routine or are able to convert this code to Python
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.