from requests import Session
s = Session()
r = s.post("https://newt.nersc.gov/newt/auth", {"username": "myuser", "password": "XXXXXXXX"})
The newt_sessionid
object is actually returned with the auth request so you don't need to dig around the cookies.
r.json()
{u'auth': True, u'newt_sessionid': u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', u'session_lifetime': 43199, u'username': u'myuser'}
Now you can just extract this newt_session_id and pass it on with a future request
newt_sessionid = r.json()['newt_sessionid']
A new session can now be initiated as long as it has the newt_sessionid string. This newt_sessionid
is a short-lived token and can be passed to other clients or servers that need access.
s2 = Session()
r = s2.get("https://newt.nersc.gov/newt/auth", cookies={'newt_sessionid': newt_sessionid})
r.json()
{u'auth': True, u'newt_sessionid': u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', u'session_lifetime': 39698, u'username': u'myuser'}