Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Requests Module & JSON Responses
    primarykey
    data
    text
    <p>I am using the awesome <a href="http://kennethreitz.com/requests-python-http-module.html" rel="nofollow">Requests module</a> 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.</p> <p>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.</p> <p>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:</p> <pre><code>\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xadZ\xfb\x8f\xd3H\x12\xfeWzG\xab;\x90 </code></pre> <p>Here are the few lines of code I am using with Requests to reproduce this issue:</p> <pre><code>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 </code></pre> <p>And I get that encoded string each time I do that.</p> <p>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.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload