import requests headers = { 'Content-type': 'application/json', } data = '{"text":"Hello, World!"}' response = requests.post('https://hooks.slack.com/services/asdfasdfasdf', headers=headers, data=data)
Here is what the above code is Doing:
1. We’re creating a dictionary called headers. This dictionary contains the headers that we’ll send to Slack.
2. We’re creating a string called data. This string contains the JSON data that we’ll send to Slack.
3. We’re sending a POST request to the Slack API. We’re sending the headers and data that we created in the previous two steps.
4. We’re storing the response from Slack in a variable called response.