Python Forum
How can I send error message to slack using webhook url in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I send error message to slack using webhook url in Python?
#1
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 -

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?
Reply


Messages In This Thread
How can I send error message to slack using webhook url in Python? - by PrateekG - Jul-18-2018, 08:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 1,047 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Send Error when attaching files JamesAinsworth 1 609 Aug-07-2023, 11:10 PM
Last Post: deanhystad
  Another Error message. the_jl_zone 2 1,000 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  email Library: properly send message as quoted-printable malonn 3 1,359 Nov-14-2022, 09:31 PM
Last Post: malonn
  Webhook, post_data, GPIO partial changes DigitalID 2 1,012 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  how to check if someone send a message in a discord channel? Zerolysimin 1 800 Nov-06-2022, 11:10 AM
Last Post: Larz60+
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,207 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  understanding error message krlosbatist 1 1,927 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
  Error message pybits 1 43,969 May-29-2021, 10:26 AM
Last Post: snippsat
  Bluetooth send message after connecting? korenron 2 2,691 Apr-26-2021, 05:50 AM
Last Post: korenron

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020