read() takes no keyword arguments

This code works well version 1.2.0

import json
from requests import Response
from cStringIO import StringIO

response = Response()
response.status_code = 400
data = {'error':'some_err'}
response.raw = StringIO(json.dumps(data))
print response.json()

but, doesn't works last version (1.2.3)  since version 1.2.1
with this error

Traceback (most recent call last):
  File "run.py", line 16, in <module>
    print response.json()
  File "D:\Python27\Env\requests\lib\site-packages\requests\models.py", line 649, in json
    if not self.encoding and len(self.content) > 3:
  File "D:\Python27\Env\requests\lib\site-packages\requests\models.py", line 600, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "D:\Python27\Env\requests\lib\site-packages\requests\models.py", line 547, in generate
    chunk = self.raw.read(chunk_size, decode_content=True)
TypeError: read() takes no keyword arguments


Hi there! Thanks for raising this issue. =)

This behaviour was changed by #1299. The change was made to address #1249. Unfortunately, replacing `Response.raw` in this way is not considered part of the public API, so could get broken by minor version updates. We have no plans to avoid passing keyword arguments to `read()`, as we expect to receive urllib3-compatible HTTP response objects.

If you want to make this work, I recommend using a custom subclass of the StringIO class that quietly drops the keyword arguments, like this:

``` python
from cStringIO import StringIO

class MyStringIO(StringIO):
    def read(self, amt=None, **kwargs):
        return super(MyStringIO, self).read(amt)
```

(I haven't tested this code so there may be some small bugs, but the general approach is right).


I do this in the tests on github3.py. Check tests/utils.py for the fix.


Thanks for reply =) 


> We have no plans to avoid passing keyword arguments to read(), as we expect to receive urllib3-compatible HTTP response objects.

The comments [in the code itself](https://github.com/kennethreitz/requests/blob/master/requests/models.py#L540-L550) tell a different story:

``` python
try:
    # Special case for urllib3.
    for chunk in self.raw.stream(chunk_size, decode_content=True):
        yield chunk
except AttributeError:
    # Standard file-like object.
    while 1:
        chunk = self.raw.read(chunk_size, decode_content=True)
            if not chunk:
                break
        yield chunk
```

Why have code to support a "standard file-like object" if they're not supported?


Hi @lukesneeringer!

If you bring up the blame on that section of code, you'll notice that I added that comment on the 18th of June, when I proposed pull request #1425, which added urllib3 code that I contributed to that library as part of shazow/urllib3#198 (merged on the 17th of June). The comment you're quoting was made on the 30th of May, more than two weeks before the code in question made it into the library. Previously there was no urllib3 special-case.

However, as you rightly point out, now there is. I think we can safely remove the arguments to the `.read()` call now, as we shouldn't be using it with urllib3.