How to post HTTP request in Python

Once upon a time, I went to attend a conference. The organizer provided wifi access to all attendances which one has to login via web before using this free service. My problem was that I would like to use secure shell. I don't want to browse web. I don't need to start web browser just for logging in. So I wrote a simple and short python script to login automatically.

#!/usr/bin/env python
 
url = 'https://login.xxx_xxx.ac.th/aaa/wba_form.html'
user = 'PKT2'
password = 'xxxxxx2007*'
 
from urllib import urlencode
from urllib2 import urlopen,Request
 
data = {
    'fname': 'wba_login',
    'username': user,
    'key': password,
}
req = Request(url,urlencode(data))
fd = urlopen(req)
print fd.read()

Tags: ,

Post new comment