Ted*_*ows 3 cas urllib3 python-requests
我还没有找到任何人使用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
Run Code Online (Sandbox Code Playgroud)
输出..注意如何将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&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)
...
...
Run Code Online (Sandbox Code Playgroud)
好的,我已经弄清楚了,所以我将为那些以后可能会发现它的人解答。问题是我不了解“表单数据”的基本概念。换句话说,该网页需要将用户名和密码输入“表单”,并且需要通过POST单击虚拟的“提交”按钮,因为它是一个“事件”(即下面的_eventId)。因此,我不得不使用'data'参数并将其全部构建为字典。这是我所做的:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2786 次 |
| 最近记录: |