简体   繁体   中英

Handling post data with requests in python

Can't login with my account in website with the following parameters:

token=...#by xpath
postdata={'token':token, 'arg1':'', 'arg2':'', 'name[user]': user, 'name[password]':password, 'arg3': 'Sign in'}
postresp=requests.post(url='http://example.com', data=postdata)
.
.
.

Should I change name[user] to name%5Buser%5D ?

Should I change name[password] to name%5Bpassword%5D ?

Should I change Sign in to Sign+in ?

arg1 and arg2 are blank. Should I remove them?

If not how can I change them? because I cant login to my account...

The requests lib already encodes your dictionaries. But if you wanna do it yourself, you should use a string. For a dict try this:

postdata={
    'token':token,
    'arg1':'',
    'arg2':'',
    'name[user]': user, # I think this should be : instead of ,
    'name[password]':password,
    'arg3': 'Sign in'}
headers={
    'Content-Type': 'application/x-www-form-urlencoded' 
    # With this header you tell the server you're sending form params
}
postresp=requests.post(url='http://example.com', headers=headers, data=postdata)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM