[Django]-CalledProcessError causes 500 error on apache even though it is (or should be) caught

3👍

If catch-all exception handling is not catching this, then either you are not running this code, or the exception in production happens outside of the try block. The 500 could even be due to an error completely outside python.

Introduce a deliberate error in this section of code and see if you see a change in behaviour in production. That at least lets you rule out the possibility of running stale code.

2👍

Thanks to Martijn Pieters’s comments and questions, I found some errors which resutled in the strange behaviour:

  • The except subprocess.CalledProcessError as e: part contained some unicode-conversions which run fine on system a and caused problems on system b. Therefore, a UnicodeConversionError was raised in my exception handling and this caused the 500 error since it was not caught.

  • An other problem in the posted code is, that unicode(sys.exc_info(), "utf-8")is raising an exception as well, because sys.exc_info() returns a tuple which is correctly converted to a string when using the str()-method, but unicode() can only deal with strings and not with tuples. One work around which did the job for me is unicode(str(...)).

Thanks to everyone who spent time in solving this question!

👤OBu

Leave a comment