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()
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
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.