Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence - 500 error when I try and update labels via requests module/python

Michael McIntyre
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 30, 2018

Hey all, 

 

I am trying to update labels via the requests module in python.  When I make a get request for the label, I get the desired data, but when I try a post request, I get a 500 error, with the error message 

"message":"javax.ws.rs.WebApplicationException: null"}

I'm not entirely sure why this is the case, but it should work.  Anyone have any ideas on troubleshooting?  My code is below:

 

def get_labels(id):
full_url = f"{BASE_URL}/{id}/label"

r = requests.get(full_url,
auth=(un, pw))

return r.json()


def format_label(labels):
final = []

for label in labels:
clean_dict = {
"prefix": "global",
"name": label
}

final.append(clean_dict)

return json.dumps(final)


def _update_label(id, labels):
data = format_label(labels)
full_url = f"{BASE_URL}/{id}/label"

r = requests.post(
full_url,
auth=(un, pw),
data=data,
headers=({"Content-Type": "appliction/json"})
)
print(r.text)


def main():
_update_label(id, labels)

main() 

 

1 answer

1 accepted

0 votes
Answer accepted
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2018

Hey Michael,

Looks like there might be a typo in your content type header. In the paste, you've got 

appliction/json

and instead will want

application/json

 (the second 'a' in application was omitted)

Have a go at that and let me know if you still have problems! Your code looks good to me, but the web server likely returned the 500 error because it didn't understand what to do with that content type.

Cheers,
Daniel

Michael McIntyre
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 4, 2018

Well, that was certainly the problem.  I'm embarrassed I got caught by a typo, but thanks so much for the help in identifying it.  Things work swimmingly now, and maybe at the very least someone can borrow the code to use later.  Thanks again!

Like Daniel Eads likes this
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 4, 2018

Awesome, glad it's working! And there's no need to feel embarrassed, I like to think of these as 'software bugs patched by the smallest possible pull request'. People frequently ask for the type of script you've written so your code will definitely help others in the future!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events