Django, python cookies, jsessionid

I am creating an application in Django that operates on a database that is populated using a face detection device that gets the face image, temperature and additional information and stores in a MySQL database. There is a legacy api that works well with the database and my app is kind of a hybrid of Django and using some endpoints of that api. My problem is that I am logging into django and also to the external (legacy) api. With django authentication is easy. For the api I need to provide a JSESSIONID cookie in order to sustain the session. For now, I am using python sessions that is instantiated in the file to send requests to the server, and every time I save some changes in the code while working, the server restarts and the also restarts thus creating a new session. Therefore I need to login again for using a new session. The question is, since this design is weak and I tried to improvise alot this month, I feel that the application can break anytime and I need to redesign this process. I have tried using custom JSESSION ids and that api could not accept some random strings as cookies. But when using a python session it works, or when working with postman generated cookies it also works. I have looked into django sessions keys and they also do not meet the requirements of the server cookies. Are cookies checked somehow? is there a way to generate a jsession id from django? PS I dont have acces to that api’s source code, i have access only to the app’s user interface and I have admin permissions on it. So I am analyzing application’s requests and using just that. I know the problem is sick, my boss just did a big mistake initiating such project lol.

You could save the JSessionID in the database in a table, and retrieve it from there. You just need to check the response every time you use it to see if the user needs to reauthenticate.