Jul-18-2018, 08:23 AM
Hi All,
I have several Python functions. In case of any error I want to send the error message to slack. For this I have added below line of code in every except block -
So can anyone please look into this and help me?
I have several Python functions. In case of any error I want to send the error message to slack. For this I have added below line of code in every except block -
except Exception as ex: msg = 'There is a problem with csv generation due to: {}'.format(ex) logger.info(msg) send_message("web_hook_url",msg)Now I have written send_message() like below mentioned in this link webhook slack post
def send_message(webhook_url, message): response = requests.post( webhook_url, data=json.dumps(message), 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) )But here I don't know how to use this function in my except block properrly. I am also not sure if it is written corrected.
So can anyone please look into this and help me?