2

I want to post password to server. Here's the server's source code(mainly):

<FORM ENCTYPE="multipart/form-data" METHOD=POST> 
Password:<INPUT NAME="pw1" TYPE="password">
Password:<INPUT NAME="pw2" TYPE="password">   
<INPUT TYPE="submit" VALUE="Confirm">

Below is my code:

import requests
url = 'http://192.168.0.1/pw'
file = {"pw1":"abc","pw2":"abc"}
r = requests.post(url, files = file)

From wireshark, I get:

--4d4bb99654064447b31a7afb787e5dbc
Content-Disposition: form-data; name="pw1"; filename="pw1"

abc
--4d4bb99654064447b31a7afb787e5dbc
Content-Disposition: form-data; name="pw2"; filename="pw2"

abc
--4d4bb99654064447b31a7afb787e5dbc--

What I expect is that there's no filename="pw1"/"pw2" i.e.,

--4d4bb99654064447b31a7afb787e5dbc
Content-Disposition: form-data; name="pw1"

abc
--4d4bb99654064447b31a7afb787e5dbc
Content-Disposition: form-data; name="pw2"

abc
--4d4bb99654064447b31a7afb787e5dbc--

The telegram can be recognized by server only in this way. How to solve handle the post request? Do I have to use files if I want to use requests library in this case? Thank you for any help.

1 Answer 1

3

For the form html you have posted, you dont have to send the input elements in files dict. The following code snippet should work -

import requests
url = 'http://192.168.0.1/pw'
data = {"pw1":"abc","pw2":"abc"}
files = {'file': ''}
r = requests.post(url, data=data, files=files)
Sign up to request clarification or add additional context in comments.

2 Comments

Yes it works. Thank you. From the guideline here, there's no such format as you posted. So is there a more detailed manual for a novice?
I am glad it worked for you. You can accept the answer then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.