0

I'm trying to submit a form using (requests) module.

Here is the form that I want to submit:

<form method="POST" enctype="multipart/form-data" action="/cgi-bin/claws72.pl"> <input type="hidden" name="email" value="[email protected]"><br> <br> Select tagset: <input type="radio" name="tagset" value="c5" checked=""> C5 <input type="radio" name="tagset" value="c7"> C7 <br><br> Select output style: <input type="radio" name="style" value="horiz" checked=""> Horizontal <input type="radio" name="style" value="vert"> Vertical <input type="radio" name="style" value="xml"> Pseudo-XML <br><br> <textarea name="text" rows="10" cols="50" wrap="virtual">Type (or paste) your text to be tagged into this box. </textarea> <br> <input type="SUBMIT" value="Tag text now"> <input type="reset" value="Reset form"> </form> 

This is the website that contains this form: http://ucrel.lancs.ac.uk/claws/trial.html

Here is my code:

import requests data = {'email' : '[email protected]', 'tagset':'c7', 'style' : 'xml', 'text' : 'TEST' } r = requests.post('http://ucrel.lancs.ac.uk/cgi-bin/claws72.pl', data=data) print(r.text) #0 words tagged (Why? it should tag the (TEST) word) print(r.ok) #True 

I use the same code with my own website form and it works, but can't figure out why it doesn't do so here! Do you think the website itself block such requests?

Thanks

2
  • Have you checked r.content? Commented Dec 25, 2017 at 10:47
  • @GarbageCollector yes, I did. But didn't find any useful info. Commented Dec 25, 2017 at 10:50

1 Answer 1

1

If You check request data using Firebug or some similar tool, You'd see that request data is actually in following format:

-----------------------------41184676334 Content-Disposition: form-data; name="email" [email protected] -----------------------------41184676334 Content-Disposition: form-data; name="tagset" c7 -----------------------------41184676334 Content-Disposition: form-data; name="style" xml -----------------------------41184676334 Content-Disposition: form-data; name="text" TEST -----------------------------41184676334-- 

Try formatting your data this way, and then try again. Also, it would be good idea to pass other request header fields (such as Accept-Encoding, Content-Type...).

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. Can you please explain what is the correct formatting? Also, I actually tried to pass all the headers values but got the same result.
Well, try to create a string which has shown structure, instead of passing a dictionary with needed values. One thing to figure out yourself is where does this 11-digit number comes from (I suppose this is some sort of anti-bot protection).
Thank you so much, you SAVED my day. I pass it as a string and it works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.