Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

401-unauthorized python rest api and curl Edited

I’m receiving a 401 Unauthorized error when trying to post attachments to the Jira Cloud.

my code in python:

##################################################

import glob
import requests
import json
import time


def upPagare(pagare):
tmp = pagare.split('.')
noAct = tmp[0]
url = 'https://pochteca.atlassian.net/rest/api/2/issue/'+noAct+'/attachments'
headers = {"X-Atlassian-Token": "nocheck"}
# please uncomment to attach external file
files = {'file': open(pagare, 'rb')}

r = requests.post(url, auth=('aferreirao@pochteca.com.mx', 'lalala'), files=files, headers=headers)
print(r.status_code)
print(r.text)


pagares = [f for f in glob.glob("*.pdf")]

for x in range(len(pagares)):
print("updating :" + pagares[x])
upPagare(pagares[x])
print("success:" +pagares[x])
time.sleep(10)

#################################################

I almost try with Curl:

 

##############################################

curl -D- -u aferreirao@pochteca.com.mx:lalala -X POST -H "X-Atlassian-Token: nocheck" -F "file=@C:\Users\aferreirao\Desktop\CAP-16041.pdf" https://pochteca.atlassian.net/rest/api/2/issue/CAP-16041/attachments

################################################

 

2 answers

1 accepted

1 vote
Answer accepted
Warren Community Leader Jul 01, 2019

Hi @Angel 

I think the issue might be that you're using a password instead of a token - see this Atlassian article for further info (there's also a link within the article with more info on using a token)

Thanks @Warren 

That was, I generated the API token and I used it

Hi,

 

I'm able to login to Jira and get the data, the problem comes with the POST method. I'm getting a 401 error, could you please help me with that. Below is my code!

 

data = {

"key": "RESV1",
"name": "Resv1",
"url": "rest/api/2/project",
"projectTypeKey": "software",
"projectTemplateKey": "TSWSIDSOT",
"lead": "*************",
"assigneeType": "PROJECT_LEAD",
"permissionScheme": 10900,
"notificationScheme": 10709,
"categoryId": 11000
}



data = json.dumps(data)

data = json.loads(data)

headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

r = requests.post(url, json=data, auth=("USERNAME", "PASSWORD"), verify=False)

print(r.json)

FYI,

 

I'm using Jira Server not Cloud

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

Confluence Bingo Round 3!

That’s right! Grandma’s back at it again, and this time she’s brought all her friends. In honor of Team '21, this Bingo round is dedicated to all things team-related, and the prizes are no exception....

413 views 13 11
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you