【问题标题】:Trouble with authorization using python使用python授权的问题
【发布时间】:2019-05-10 20:16:17
【问题描述】:

我正在运行以下脚本来登录我大学的强制门户:

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>

我可以做些什么来解决这个问题?

【问题讨论】:

  • 网站使用什么样的身份验证? HTTP 基本身份验证,还是其他?

标签: python python-3.x http python-requests


【解决方案1】:

为了解决这个问题,我开始比较我发送的数据包和通过使用 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()

瞧,它开始工作了,但我不知道为什么。如果有人可以向我解释为什么它现在可以工作,那就太好了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-19
    • 2015-07-03
    • 2011-07-12
    • 2017-12-17
    • 1970-01-01
    • 2018-02-16
    相关资源
    最近更新 更多