我还没有找到任何利用Python来通过CAS的人的例子。希望也许Kenneth Reitz可以告诉我'请求'可以如何简单...Python请求和CAS
基本上,我无法通过CAS登录...从不验证我的Python尝试。 (请注意,我定义了两个网址.... url1是主网页,url2是CAS网站的重定向链接...我已经知道重定向链接,因此使它变得简单)。
我的理解是我所要做的就是捕获CAS发送给我的JsessionId作为cookie,然后获取该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&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)
...
...
对于记录,你可以接受你自己的答案 – TankorSmash