import
requests
import
sys
def acces_api_with_cookie(url_login, USERNAME, PASSWORD, url_access):
# Start a session so we can have persistant cookies
session = requests.session()
# This is the form data that the page sends when logging in
login_data = {
'username'
: USERNAME,
'password'
: PASSWORD,
'submit'
:
'login'
,
}
# Authenticate
r = session.post(url_login, data=login_data)
# Try accessing a page that requires you to be logged in
r = session.get(url_access)
print r.content
acces_api_with_cookie(
'http://127.0.0.1:88/accounts/login/'
,
'admin'
,
'123456'
,
'http://127.0.0.1:88/accounts/user_list/'
)