Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Catch all curl exceptions
#1
Just want to find a way to catch all exceptions curl may throw. I was using urllib on cpython and I occasionally got exceptions such as urllib.error.URLError or urllib.error.HTTPError. I am not a seasoned python programmer but I want to catch these exceptions so my data logging script won't quit because one data point didn't make it to the server.

Is there a way to catch all exceptions thrown by a particular module and print out the message so I can later investigate instead of catching all the exceptions of every kind.

Everything seems to be in this C code but I don't know how to do it.

https://github.com/loboris/MicroPython_E...url/curl.h


Thanks.
Reply
#2
Not sure about curl module as I haven't used it yet but this is what I use for all the modules thta I use and I assume it should also work for curl https://docs.python.org/3/tutorial/errors.html
Reply
#3
You can useĀ curl.options(verbose=True) to get detailed report about curl operations.
Reply
#4
The with statement in Python simplifies exception handling by encapsulating common preparation and clean-up tasks in so-called context managers. This allows common try..except..finally usage patterns to be encapsulated for convenient reuse and reduce the amount of code you need to write for handling different kinds of exceptions. The with statement creates resources within a block . You write your code using the resources within the block. When the block exits the resources are cleanly released regardless of the outcome of the code in the block (that is whether the block exits normally or because of an exception).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)