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

How to post a .png file to a hipchat room using python?

I have an image file my_image.png saved in a local directory, and I am trying to post that file to a hipchat room.

I found this and tried it but got the below error:

{
"error": {
"code": 403,
"message": "Only requests matching one of these authenticated principals are allowed to access this resource: an active user",
"type": "Forbidden"
}

I also created a python function after looking around the internet below:

def hipchat_send_file(image_file, token=TOKEN, room=ROOM, color='green', notify=False, host='myhostname.com'):
url = "https://{0}/v2/room/{1}/share/file".format(host, room)
headers = {'Content-Type': 'multipart/related; boundary=boundary123456'}
headers['Authorization'] = "Bearer " + token


files = {'file': (open(image_file, 'rb'), 'image/png')}

r = requests.post(url, files=files, headers=headers)
print(r.status_code)
print(r.text)

and I got the same exact error as above:

{
"error": {
"code": 403,
"message": "Only requests matching one of these authenticated principals are allowed to access this resource: an active user",
"type": "Forbidden"
}

Can anyone help?  Thanks.

1 answer

1 accepted

0 votes
Answer accepted

Hi Patricia, 

We have the following API that can help you share a file to a HipChat room easily:

Let me know if you have additional questions about it.

Hi Nagila,

Yes, I have looked into that. I found this for my specific question, and it works.

Thank you for your help.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Hipchat

Hipchat Cloud and Stride have reached End of Life (updated)

All good things come to an end - thanks to all our customers and partners who have been along the Hipchat and Stride journey with us.  As of Feb 15th 2019, Hipchat Cloud and Stride have reached ...

35,198 views 9 8
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