Created
August 14, 2023 19:26
-
-
Save wiljdaws/76e1053a8ee46901e7f473640c4c556a to your computer and use it in GitHub Desktop.
Send dictionary to slackbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_to_slackbot(dictionary_object: dict, webhook_string: str): | |
''' | |
This function sends the dictionary object to the slackbot | |
Args: | |
- dictionary_object (dict): dictionary object | |
- webhook_string (str): webhook string | |
Raises: | |
ValueError: if response status code is not 200 | |
Return type: None | |
''' | |
data=json.dumps(dictionary_object) | |
response = requests.post( | |
webhook_string, data, | |
headers={'Content-Type': 'application/json'} | |
) | |
if response.status_code != 200: | |
raise ValueError( | |
'Request to slack returned an error %s, the response is:\n%s' | |
% (response.status_code, response.text) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment