简体   繁体   English

我的python自动登录脚本已损坏

[英]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. 很久以前,我写了一个小python脚本来自动将我登录到办公室的无线网络。

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)
    form = 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. 这看起来好像我没有安装某些软件包(ClientForm),所以我安装了它(sudo port install py-clientform),但仍然收到相同的错误。 Does anyone have an idea what I'm doing wrong? 有人知道我在做什么错吗?

Also check that the package you installed is in python path: 还要检查您安装的软件包是否在python路径中:

>>> 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 eg "username" same with "password". Once again wireshark would help with this. Also could look at source of login page. Good luck!!!) (能够通过wireshark获取站点以发送数据。“ user”也可能是其他名称,例如与“ password”相同的“ username”。wireshark会对此有所帮助。也可以查看登录页面的来源。祝您好运! !!)

from urllib import urlencode
from urllib2 import Request, urlopen

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM