# Get SessionID with requests

**URL:** <https://forum.inductiveautomation.com/t/get-sessionid-with-requests/65197>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [October 13, 2022, 5:29pm UTC](https://forum.inductiveautomation.com/t/get-sessionid-with-requests/65197 "2022-10-13T17:29:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [October 13, 2022, 5:29pm UTC](https://forum.inductiveautomation.com/t/get-sessionid-with-requests/65197/1 "2022-10-13T17:29:25Z")

</div>

> [@Scripting to read gateway logs](https://forum.inductiveautomation.com/t/scripting-to-read-gateway-logs/64402/3):
>
> Ah, I started going the approach of hitting the `http://localhost/data/status/logs` endpoint, but was struggling with getting a `JSESSIONID`. Any ideas on how to get that with the builtin Ignition IDP enabled?

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

```auto
import requests

url = "http://localhost/data/status/diagnostics/threads/threaddump"
contentType = "application/json"
jsessionid="JSESSIONID=node01la3zauakwhljdd4x63ivwrps1.node0"

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:
            f.write(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?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 13, 2022, 5:40pm UTC](https://forum.inductiveautomation.com/t/get-sessionid-with-requests/65197/2 "2022-10-13T17:40:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [October 13, 2022, 6:56pm UTC](https://forum.inductiveautomation.com/t/get-sessionid-with-requests/65197/3 "2022-10-13T18:56:14Z")

</div>

> [@Kevin.Herron](#):
>
> If you can figure out how to get a valid JSESSIONID that's good for you, but it's not supported.

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:

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

```
