Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a Post Request in Python?

Hi I'm sitting in a Greyhound Bus with Wifi and want to connect a second Device to the Network. But I have to accept an onscreen contract and the device does not have a browser. To accept the contract the following form has to be accepted. The device has no CURL but all the standard python 2.6. libraries.

<form method="POST" name="wifi" id="wifi" action="http://192.168.100.1:5280/">  
  <input type="image" name="mode_login" value="Agree" src="btn_accept.gif" />  
  <input type="hidden" name="redirect" value="http://stackoverflow.com/">       
</form>

How would I write a quick python script to accept the contract?

like image 420
Janusz Avatar asked Oct 06 '09 18:10

Janusz


1 Answers

I think this should do the trick:

import urllib
data = urllib.urlencode({"mode_login":"Agree","redirect":"http://stackoverflow.com"})
result = urllib.urlopen("http://192.168.100.1:5280/",data).read()
print result
like image 197
Kimvais Avatar answered Oct 09 '22 01:10

Kimvais