How to connect to and keep the session alive using python requests
Question: I am trying to login to a site, and then view user details.

The API documentation from the site is:

    
    
    LogOn : All Calls with JSON and return JSON type
    
    post - https://www.bit2c.co.il/Account/LogOn  {UserName:'',Password:'',SecondFactor:[optional]} 
    return true if OK , error list of strings if not
    
    Balance - GET https://www.bit2c.co.il/Account/Balance
    return UserBalance as JSON  
    

I've tried connecting to the site using

    
    
    import requests
    session=requests.session()
    session.auth = ("username", "pass")
    session.post("https//www.bit2c.co.il/Account/Balance")
    

but i am getting response 200 and the response content is "you must login".

What am I doing wrong ?


Answer: What kind of _session_? What is on server-side? Can you post the raw
request/response pair(s)?

If PHP or ASP runs on server-side, you must capture the `Set-Cookie` header of
the response to the login request, find the session cookie and in consequent
requests you must set the `Cookie` header with the session cookie name and
value captured previously.

