Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST with file param not setting multipart/form-data? #166

Open
tonyblank opened this issue Aug 14, 2014 · 6 comments
Open

POST with file param not setting multipart/form-data? #166

tonyblank opened this issue Aug 14, 2014 · 6 comments

Comments

@tonyblank
Copy link

I'm trying to make a multipart/form-data POST and can't figure out how to set the content-type to multipart/form-data. It's 'content-type': 'application/x-www-form-urlencoded'. - That's strange to me because I see the boundary in the body..

When I manually set the content-type header to multipart/form-data, then there's no boundary defined...

@maxcountryman
Copy link
Contributor

Can you provide more context, how about a code sample that demonstrates the issue?

@anssih
Copy link

anssih commented Dec 28, 2014

For e.g. POST, OAuth1Session.request() does
req_kwargs['headers'].setdefault('Content-Type', FORM_URLENCODED).

This seems to override the proper "multipart/form-data" content type which PreparedRequest.prepare_body() gets from self._encode_files().

Overriding it manually using headers parameter for session.post() won't work since the content-type field needs to contain the boundary information which the rauth user doesn't know.

I workarounded this locally by making this modification:

         entity_method = method.upper() in ENTITY_METHODS
-        if entity_method:
+        if entity_method and not req_kwargs.get('files', None):
             req_kwargs['headers'].setdefault('Content-Type', FORM_URLENCODED)

@maxcountryman
Copy link
Contributor

@anssih mind submitting a patch for that?

@davidkhess
Copy link
Contributor

+1

This stumped me for a couple of hours when trying to upload to twitter's media/upload endpoint.

Same fix worked.

@maxcountryman
Copy link
Contributor

@davidkhess patches welcome. :)

davidkhess added a commit to davidkhess/rauth that referenced this issue Apr 3, 2015
@davidkhess
Copy link
Contributor

Ok, you guilted me into it. :-)

maxcountryman added a commit that referenced this issue Apr 6, 2015
Fix for #166 - Content-Type is being overridden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants