Get SessionID with requests

I need to download thread dumps through an external system, and I know that the following script works to do so:

import requests

url = "http://localhost/data/status/diagnostics/threads/threaddump"
contentType = "application/json"

headers = {
    'Content-Type': contentType,
    'Cookie': jsessionid

# The response will be a file, save that file
response = requests.request("GET", url, headers=headers, stream=True)

with open('threaddump.json', 'wb') as f:
    for chunk in response.iter_content(chunk_size=1024):
        if chunk:

The problem is that the JSESSIONID needs to be provided or the endpoint is forbidden. I have been struggling to get a JSESSIONID first with the built in IDP, any ideas on how to do that?

Some day we're going to have a first class way to manage auth tokens for accessing all the endpoints the gateway config pages do, but for now you're pretty much out of luck. If you can figure out how to get a valid JSESSIONID that's good for you, but it's not supported.

In the meantime you'd be better off putting this functionality behind a WebDev endpoint instead.


Makes sense, can't argue with that!

However I did figure it out for anyone curious, but this only works if your status page does not have security enabled:

session = requests.Session()
session.get(host + 'web/home')
cookies = session.cookies.get_dict()
JSessionID = cookies['JSESSIONID']