I want to take the password from the user and then send a post request to a url ('http://example.com/welcome?user='
+ (some user name)). So how can I send a post request with data?
data = {'password': SOME_PASSWORD}
requests.post(url, data=data)
your url would be something like
'http://example.com/welcome?user={}'.format(username)'
Then at you server you have the username in the get parameters and password in the post parameters. But the you could just put the user and the password in the data dictionary and post both fields
EDIT:
I do agree with Martijn that passing some data in get and some in post is a bad idea, so if there is not a good reason to do it you probably should avoid it.
I also like the idea of using the requests params argument and data arguments if you absolutely need to pass them the username in GET and the password in POST, so your request would become:
requests.post('http://example.com/welcome', data={'password': SOME_PASSWORD}, params={'user': SOME_USERNAME})
but the best way is:
requests.post('http://example.com/welcome', data={'password': SOME_PASSWORD, 'user': SOME_USERNAME})
Apologies for the short answer previously, it was a quick one in a coffee break. Please forgive me :-)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments