I am using the awesome Requests module to test an API I've created for one of our internal projects. I believe I have discovered what is either a flaw in the Requests module itself, or a flaw in my usage of it.
Because our data is not super sensitive, our API uses simple, basic HTTP authentication to control acces. When I make requests of the API URL, using JSON as the data format and either urllib2 with HTTPBasicAuthHandler or PHP and cURL, I get my data back as a properly formatted JSON string - no problem.
However, when I make the same request using the Requests module, I get back an encoded string, and I cannot determine what type of encoding it is. Here is a snippet of the beginning of that string:
\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xadZ\xfb\x8f\xd3H\x12\xfeWzG\xab;\x90
Here are the few lines of code I am using with Requests to reproduce this issue:
import requests
# api_user and api_pw not printed here for security reasons
r = requests.get('http://ourdomain.com/api/featured/school/json', auth=(api_user, api_pw))
status = r.status_code # Produces 200 every time
rawdata = r.read()
print rawdata
And I get that encoded string each time I do that.
Can anyone help me to determine: a) What encoding that is (for my own edification), and b) Why Requests is returning data in that encoding, and how to decode and/or "fix" it.
Thanks in advance!