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

Parse form data as python dict literal when appropriate #29

Closed
caymard opened this issue Oct 14, 2016 · 2 comments
Closed

Parse form data as python dict literal when appropriate #29

caymard opened this issue Oct 14, 2016 · 2 comments
Assignees
Labels

Comments

@caymard
Copy link

caymard commented Oct 14, 2016

Hi

First of all thanks for your useful tool.

I had an issue by parsing the following curl command:

curl -X POST -d "grant_type=client_credentials" -u "foo:bar" http://localhost/api/oauth/token/

Your tool returns this:

data = 'grant_type=client_credentials'
requests.post('http://localhost/api/oauth/token/', data=data)

First, as mentioned in #24, -u option is not processed.
Second, the data field does not work in requests. To make it work, I had to change the first line for data = {'grant_type':'client_credentials'}.
In conclusion, your tool should have return this:

data = {'grant_type': 'client_credentials'}
user = ('foo', 'bar')
requests.post('http://localhost/api/oauth/token/', data=data, auth=user)

Regards,

Clément

Usefull links:

@NickCarneiro NickCarneiro self-assigned this Oct 17, 2016
@NickCarneiro NickCarneiro changed the title -d did not parse correctly for Python requests Parse form data as python dict literal when appropriate Oct 17, 2016
@NickCarneiro
Copy link
Member

It looks like the only different between a string
data = 'grant_type=client_credentials'
and a dict literal
data = {'grant_type': 'client_credentials'}

is that the dict literal magically adds a content-type header.

Content-Type: application/x-www-form-urlencoded

I'm going to add support for dict literals when the input string looks like it's a series of url-style keys and values.

@NickCarneiro
Copy link
Member

Fixed in 0.0.28 for python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants