Trying to post a message to MS Teams webhook from Python below:
pmr = urllib3.PoolManager()
text='hello world'
message = {"Test":text}
enco_message = json.dumps(message).encode('utf-8')
r=pmr.request('POST',url, headers={'Content-Type': 'application/json'}, body=enco_message)
print(r.status)
But this does not send any message to teams and returns response status 400
. Not sure what is to be changed in the code. Thanks for the help.
This worked by explicitly specifying text
keyword in the json
, like below:
pmr = urllib3.PoolManager()
msg='hello world'
message = {"text":msg}
enco_message = json.dumps(message).encode('utf-8')
r=pmr.request('POST',url, headers={'Content-Type': 'application/json'},
body=enco_message)
The payload only works with the keyword text
.