This is because python str.encode('base64') inserts newlines every 78 characters and also an the end of the returned string. If the base64 encoded credentials exceeded a single line, the intermediate line breaks would be inserted right into the HTTP headers and cause a malformed request.
…handling method This was happening because a malformed request would cause an error at the web-server level and thus would request HTML instead of JSON. The error handling was always expecting JSON, and thus this would fail with a not-so-helpful message.
…doesn't automatically force the connection to close via the 'Connection: close' header. Changed some double quotes to single quotes.
was moved there.
…now handle that case using a custom urllib2 opener.
…new test calls to main().