如何对请求执行HTTP/XML身份验证



我正在尝试使用请求2.7验证Python 3.4的Docushare。我对Python和请求模块相对较新,但我已经做了很多阅读,并且无法取得任何进展。我的代码没有给出任何错误,我从我的post请求中收到一个JSESSIONID cookie,但我没有得到AmberUser身份验证cookie。我不知道如何进一步调查以找出问题所在。

请求的形式来自http://docushare.xerox.com/en-us/Help/prog/prog5.htm#Authentication

请求:

POST  /dscgi/ds.py/Login  HTTP/1.1
Host:  docushare.xerox.com
Content-Type: text/xml
Content-Length: xxxx
<?xml version="1.0" ?>
<authorization>
  <username>msmith</username>
  <password>mysecretstring</password>
</authorization>

我的Python/requests代码如下:

import requests
url = "https://mydocusharesite/dsweb/Login"
xml="""<?xml version='1.0' ?>
<authorization>
<username>myusername</username>
<password><![CDATA[mypa$$word]]></password>
<domain>DocuShare</domain>
</authorization>"""
headers = {"DocuShare-Version":"5.0", 'Content-Type':'text/xml'}
s = requests.Session()
r = s.post(url,data=xml,headers=headers)
print('Status code:', r.status_code)
print('headers:n', r.headers)
print('request headers:n',r.request.headers)
c = s.cookies
print('Cookies:n', c)
我得到的输出是

Status code: 200
headers:
 {'set-cookie': 'JSESSIONID=21B7E5E0D83D1F1267371B9FD1B19BBC.tomcat1; Path=/docushare; Secure', 'transfer-encoding': 'chunked', 'connection': 'close', 'content-type': 'text/html;charset=UTF-8', 'cache-control': 'private', 'date': 'Sun, 07 Jun 2015 02:22:59 GMT', 'expires': '-1'}
request headers:
 {'Connection': 'keep-alive', 'DocuShare-Version': '5.0', 'Accept': '*/*', 'Content-Type': 'text/xml', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': '153', 'User-Agent': 'python-requests/2.7.0 CPython/3.4.3 Darwin/14.3.0'}
Cookies:
 <RequestsCookieJar[<Cookie JSESSIONID=21B7E5E0D83D1F1267371B9FD1B19BBC.tomcat1 for mydocusharesite>]>

您的CDATA部分应该看起来像<![CDATA[mypa$$word]]>。您的代码目前正在发送![CDATA[mypa$$word]]作为实际密码。

最新更新