gpt4 book ai didi

cas - Python 请求和 CAS

转载 作者:行者123 更新时间:2023-12-01 11:01:04 26 4
gpt4 key购买 nike

我还没有找到任何人使用 Python 来通过 CAS 的例子。希望 Kenneth Reitz 可以向我展示“请求”如何让这一切变得简单......

基本上,我无法通过 CAS 登录...从不验证我的 Python 尝试。 (注意,我定义了两个 url……url1 是主网页,url2 是到 CAS 站点的重定向链接……我已经知道重定向链接,所以很容易)。

我的理解是我所要做的就是捕获 CAS 作为 cookie 发送给我的 JsessionId,然后获取该 cookie 并将 jsessionid 附加回 url 并将其作为 POST 发送回 CAS用户名密码)。然而,这个脚本每次都会失败。

一些 CAS 专家可以帮助我吗?我根本无法弄清楚为什么它不会对我进行身份验证。

import sys
import requests

my_config = {'verbose': sys.stderr }

url1 = 'http://agnes:8080'
url2 = 'https://agnes:8543/irisCAS/login?service=http%3A%2F%2Fagnes%3A8080%2FirisRootWeb%2Fj_spring_cas_security_check'

response = requests.get(url1, headers=headers, verify=False)
print response.cookies

cookies = response.cookies
response = requests.post(url2, headers=headers, verify=False, config=my_config, params=cookies, auth=('username', 'password'))

print response.status_code
print response.content

输出 ....注意 jsessionId 是如何附加到 url2 的,所以这很好......我认为。

{'JSESSIONID': 'EEE38382A1D5AAACA58E12433BDA0BFF'}

2012-05-18T15:04:17.668601 POST https://agnes:8543/irisCAS/login?service=http%3A%2F%2Fagnes%3A8080%2FirisRootWeb%2Fj_spring_cas_security_check&JSESSIONID=EEE38382A1D5AAACA58E12433BDA0BFF

200

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
...
...
</script>

<form id="fm1" class="fm-v clearfix" action="/irisCAS/login;jsessionid=30ABCAC79FEA5B48399053939530A608?service=http%3A%2F%2Fagnes%3A8080%2FirisRootWeb%2Fj_spring_cas_security_check&amp;JSESSIONID=B6235434D64C5E2E6C063BA3E1C1AC43" method="post">

<div class="box fl-panel" id="login">
<!-- Congratulations on bringing CAS online! The default authentication handler authenticates where usernames equal passwords: go ahead, try it out. -->
<h2>Enter your UserId and Password</h2>

(this is just the xml of the CAS login page that I can't get past)

...
...

最佳答案

好的,我想通了,所以我会为以后可能会发现这个问题的人回答这个问题。问题是我不明白“表单数据”的基本概念。换句话说,网页需要将用户名和密码输入到“表单”中,并且需要通过 POST 单击虚拟“提交”按钮,因为它是一个“事件”(即下面的 _eventId)。所以我不得不使用“数据”参数并将所有这些构建为字典。这就是我所做的:

payload = {'_eventId': 'submit', 'lt': 'e1s1', 'submit': 'LOGIN', 'username': 'admin', 'password': 'admin'}
sessionResp = sessionReq.post(url2, data=payload, params=cookies, verify=False, config=my_config, headers=headers)

关于cas - Python 请求和 CAS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10659124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com