开发者

My python auto-login script is broken

A long time ago, I wrote a little python script to automatically log me on to the wireless network at my office.

Here is the code:

#!/opt/local/bin/python
from urllib2 import urlopen
from ClientForm import ParseResponse

try:
if "Logged on as" in urlopen("https://MYWIRELESS.com/logon").read():
    print "Already logged on."
else:
    forms = ParseResponse(urlopen("https://MYWIRELESS.com/logon"), backwards_compat=False)
    开发者_如何学Goform = forms[0]
    form["username"], form["password"] = "ME", "MYPASSWD"
    urlopen(form.click())
    print "Logged on. (probably :-)";
except IOError, e: print "Couldn't connect to wireless login page:\n", e

I changed computers recently, and it stopped working. Now, I get the error:

File "login.txt", line 4, in <module>
    from ClientForm import ParseResponse
ImportError: No module named ClientForm

which makes it look like I don't have some package (ClientForm) installed, so I installed it (sudo port install py-clientform), but I still get the same error. Does anyone have an idea what I'm doing wrong?


Also check that the package you installed is in python path:

>>> import sys
>>> sys.path


This worked for something similar:

(Was able to get site to send data using wireshark. Also "user" might be something else e.g. "username" same with "password". Once again wireshark would help with this. Also could look at source of login page. Good luck!!!)

from urllib import urlencode
from urllib2 import Request, urlopen

req = Request('www.site.com',urlencode({'user':'userhere', 'password':'passwordhere'}))
open = urlopen(req)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜