How to perform an HTTP/XML authentication with requests

2024/10/15 13:20:44

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.

The form of the request comes from http://docushare.xerox.com/en-us/Help/prog/prog5.htm#Authentication

Request:

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>

My Python / requests code looks like:

import requestsurl = "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)

The output I get is

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>]>
Answer

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

https://en.xdnf.cn/q/117829.html

Related Q&A

webPy Sessions - Concurrent users use same session and session timeout

I have a webPy app using sessions for user authentication. Sessions are initiated like so:web.config.debug=Falsestore = web.session.DiskStore(/path_to_app/sessions) if web.config.get(_session) is None:…

get text content from p tag

I am trying to get description text content of each block on this page https://twitter.com/search?q=data%20mining&src=typd&vertical=default&f=users. html for p tag looks like<p class=&q…

Python - making a function that would add - between letters

Im trying to make a function, f(x), that would add a "-" between each letter:For example:f("James")should output as:J-a-m-e-s-I would love it if you could use simple python function…

python script keeps converting dates to utc

I have the following:import psycopg2 from openpyxl import Workbook wb = Workbook() wb.active =0 ws = wb.active ws.title = "Repair" ws.sheet_properties.tabColor = "CCFFCC"print(wb.sh…

sklearn tsne with sparse matrix

Im trying to display tsne on a very sparse matrix with precomputed distances values but Im having trouble with it.It boils down to this:row = np.array([0, 2, 2, 0, 1, 2]) col = np.array([0, 0, 1, 2, 2,…

Removing a sublist from a list

I have a list e.g. l1 = [1,2,3,4] and another list: l2 = [1,2,3,4,5,6,7,1,2,3,4]. I would like to check if l1 is a subset in l2 and if it is, then I want to delete these elements from l2 such that l2 …

Python double FOR loops without threading

Basically, I want to make a grid with school subjects and all the test results I got from it, and I want to display about 10 results for every subject.Like this:... ------------------------------------…

Challenging way of counting entries of a file dynamically

I am facing a strange question, which despite of trying many times, i am not able to find the logic and proper code to the problem. I have a file in the format below: aa:bb:cc dd:ee:ff 100 ---------…

NSException on import of matplotlib, kivy in OSX

Im working on some kivy code thats working fine on windows 10, but crashes on osx sierra, Ive isolated that the crash happens when I import kivy.core.window along side matplotlib: import matplotlib mat…

strange behavior with lamba: getattr(obj, x) inside a list [duplicate]

This question already has answers here:Creating functions (or lambdas) in a loop (or comprehension)(9 answers)Closed 11 years ago.In the following example:class A(object):passprop1 = 1prop2 = 2prop3 = …