我还没有找到任何使用Python来通过CAS的人的例子。希望Kenneth Reitz可以告诉我'请求'如何让这一切变得简单......
基本上,我无法通过CAS登录...永远不会验证我的Python尝试。 (注意,我定义了两个网址.... 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
OUTPUT ....注意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)
...
...
答案 0 :(得分:5)
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)