Fixes bug where a malformed request would cause a crash of the error 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.
Long credentials would cause an HTTP Basic Auth to fail

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.
Merge remote-tracking branch 'thanosd/master' into thanosd