我正在运行以下脚本来登录我的大学的俘虏门户:
import requests
values = {'username':'cisco','password':'cisco'}
r = requests.post('http://10.163.0.1/login',data=values)
print(r.text)
我得到以下输出:
<html>
<body>
<center>
If you are not redirected in a few seconds, click 'continue' below<br>
<form name="redirect" action="https://muj.i-on.in/" method="post">
<input type="hidden" name="mac" value="7C:76:35:F4:73:56">
<input type="hidden" name="ip" value="10.163.5.38">
<input type="hidden" name="username" value="cisco">
<input type="hidden" name="link-login" value="http://10.163.0.1/login">
<input type="hidden" name="link-orig" value="">
<input type="hidden" name="error" value="Could not locate user
profile from context for authorization: c">
<input type="hidden" name="chap-id" value="">
<input type="hidden" name="chap-challenge" value="">
<input type="hidden" name="link-login-only" value="http://10.163.0.1/login">
<input type="hidden" name="link-orig-esc" value="">
<input type="hidden" name="mac-esc" value="7C%3A76%3A35%3AF4%3A73%3A56">
<input type="hidden" name="interface-name" value="B2_Hostel-163">
<input type="submit" value="continue">
</form>
<script language="JavaScript">
<!--
document.redirect.submit();
//-->
</script>
</center>
</body>
</html>
由于以下错误,我无法登录:
<html>
<input type="hidden" name="error" value="Could not locate user
profile from context for authorization: c">
</html>
我该怎么做才能解决此问题?
答案 0 :(得分:0)
为解决此问题,我开始比较我正在发送的数据包和使用Chrome登录后发送的数据包(我使用Wireshark分析了这些数据包),而chrome发送的数据包包含的内容更多:
key: "radius1-44115"
value: "12"
所以在我的代码中,我也像这样发送了
import requests
values={'username':'cisco','password':'cisco','radius1-44115':'12'}
try:
r=requests.post('http://10.163.0.1/login',data=values)
print('Connected')
except:
print('Attempt to authencticate failed,Re-trying......')
connect()
瞧,它开始工作了,我不知道为什么。如果有人可以向我解释为什么现在可以正常工作,那就太好了。