如何对请求执行HTTP/XML身份验证 [英] How to perform an HTTP/XML authentication with requests

查看:65
本文介绍了如何对请求执行HTTP/XML身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用请求2.7使用Python 3.4对Docushare进行身份验证.我对Python和请求模块比较陌生,但是我已经读了很多书,无法取得更多进展.我的代码没有给出任何错误,我从发帖请求中收到了JSESSIONID cookie,但是我没有得到AmberUser身份验证cookie.我不知道如何进一步调查以找出问题所在.

I am trying to authenticate to Docushare with Python 3.4 using requests 2.7. I am relatively new to Python and to the requests module but I've done a lot of reading and am not able to make any more progress. My code doesn't give any errors and I receive a JSESSIONID cookie back from my post request, but I'm not getting the AmberUser authentication cookie. I don't know how to investigate this further to find out what the problem is.

请求的形式来自 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/请求代码如下:

My Python / requests code looks like:

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]] 作为实际密码.

Your CDATA section should look like <![CDATA[mypa$$word]]>. Your code is currently sending ![CDATA[mypa$$word]] as the actual password.

这篇关于如何对请求执行HTTP/XML身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆