How to upload file using mechanize python?

117 Views Asked by At

I need to upload a file(txt) in a form like this:

press to upload file

the structure of the add button is as follows:

code of add button

after upload I have to send the file with the send button:

enter image description here

the structure of the send button is as follows:

enter image description here

I searched and found only examples like this:

browser.select_form(name = 'formForm')
browser.form.add_file(open(directory))
response = browser.submit()

but I didn’t succeed, if anyone can help me thank you very much

1

There are 1 best solutions below

6
On

this is what you're looking for:

br.form.add_file(open(filename), 'text/plain', filename)