Can you explain how the middle options don't work? If res is None, I'd think either of the first two clauses of your or expression should catch it. If it's something other than None, I'd expect you to get a different exception. What is the contents of req.text when you say it's length 16?