0

Facing issue while send the local image to google chat room using web hook.

attachment = open("images.jpg", "rb")
bot_message = {"cards": [{ "sections": [{"widgets": [{"image": attachment}]}]}]}
print (bot_message)
message_headers = {'Content-Type': 'application/json; charset=UTF-8'}

Error:

TypeError: Object of type BufferedReader is not JSON serializable

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

Issue roots from BufferedReader not JSON serializable which is caused by image widget expecting a URL instead.

Alternative is that, you need to upload your file to an image hosting site first (e.g. imgur) and then use the url of the posted image to the image widget's image url. For this one, see Imgur API docs.

Reference:

NightEye
  • 10,634
  • 2
  • 5
  • 24
  • Many Thanks. is there possibilities to send locally stored images? – Mani Bharathi Jul 30 '21 at 02:34
  • Based on the provided documentation and other posts here, I was not able to confirm if locally stored images are possible (right now, it is safe to assume it is impossible). You would have to upload the images to a image hosting site first via api and then use the link generated for that upload in your image widget parameter – NightEye Jul 30 '21 at 14:50
  • hi @ManiBharathi, If we answered your question, please click the accept button on the left (check icon). By doing so, other people in the community, who may have the same concern as you, will know that theirs can be resolved. If the accept button is unavailable to you, feel free to tell me. [how to accept answer](https://stackoverflow.com/help/accepted-answer) – NightEye Jul 30 '21 at 14:51