'requests.post only accepts "text" dictionary values
I'm attempting to make post requests to slack from a requests.post() call. Here is an example of the code that I've made to do this:
fields = {
'sender': message['From'],
'subject': message['Subject'],
}
url = 'https://hooks.slack.com/services/XXXXXX'
print(fields)
return requests.post(url, json=fields)
The issue seems to be that the requests.post(url, json=fields) command only seems to respond to the fields command if I change the key value(s) to "text". I have no idea what is not allowing the requests.post command to use other key values (such as sender or subject) that I have defined here.
I have been able to fix this by doing a terrible workaround of calling two separate requests.post commands and setting sender/subject as their own variables with json formatted dictionaries:
sender = {'text': message['From']}
subject = {'text': message['Subject']}
Just a side-note I'm gathering these message handlers from aiosmtpd.handlers which allows me to parse smtp messages that come in.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
