Today on work on a python related mailing list someone sent this snippet of code he didn’t wrote.
and that was causing some of the server he worte/manged some troubles.
Here’s the code:
First thought I hade was, the one wrote it is must be coming from C (or maybe Java), so let go over what’s wrong here.
Input validation
I don’t know what’s print_error_exit() is doing exactly, let’s assume it’s raising expection (hopefully it’s not calling os.exit())
So assertion with the proper text would be alsmot identical.
Checking both for None, and for empty string is futile, just assert, like this:
Using requests to stream file
Requests is cool, alsmot the defacto standard when HTTP client is need in python.
it has very good documention, clearly someone didn’t read it.streaming uploads
Multiple error paths
Lot of different error handling code, one for checking the http statuses and one for catching expections.