kennethreitz/requests — Issue #292: Accept file-like objects as request data
Author: zacharyvoase
Created: 2011-11-28 16:42:28+00:00
State: open

I'd like it to be possible to pass in a file-like object as the source of request data, provided `content-length` and `content-type` headers have been specified already. Here's an example of what I'd like to do:

response = requests.put(
'http://example.com/endpoint',
data=open('filename', 'rb'),
headers={
"Content-Type": "text/plain",
"Content-Length": os.stat('filename').st_size})

Alternatively, requests could even recognise that I've passed in a `File` object and perform an `os.fstat(file_like_obj.fileno())` automatically.

Here's the bit of code that seems to be breaking:

https://github.com/kennethreitz/requests/blob/c7b99f78192bdff62fad4f92039396c0dfbe4fb8/requests/models.py#L267

When I pass in an object that is neither a string nor a dictionary, the call to `dict()` fails.

I'm able and willing to work on this in a fork, I just figured it would be better to submit it as an issue first.