title: How to maintain session while navigating a website using Python- 401 error
body: <p>I am trying to write a Python script that logins to a website and navigate to a link post successful login. I am unable to maintain the session when I navigate to other links.</p>
  
  <p>I tried to do it by using Requests import. I am able to login to the website and getting 401 error when I navigate to other page.</p>
  
  <pre><code>import requests
  from lxml import html
  
  USERNAME = "AMITHSR"
  PASSWORD = "******"
  
  LOGIN_URL = "https://login.apigee.com/login"
  TARGET_URL = "https://apigee.com/organizations/amithsr77-eval/proxies"
  
  
  def main():
      session_requests = requests.session()
  
      # Get login csrf token
      result = session_requests.get(LOGIN_URL)
      tree = html.fromstring(result.text)
      authenticity_token = list(set(tree.xpath("//input[@name='X-Uaa-Csrf']/@value")))[0]
  
      # Create payload
      payload = {
          "username": USERNAME,
          "password": PASSWORD,
          "X-Uaa-Csrf": authenticity_token
      }
  
      # Perform login
      result = session_requests.post(LOGIN_URL, data=payload, headers=dict(referer=LOGIN_URL))
      print(result)
  
      page = session_requests.get(TARGET_URL)//401 error is here
      tree2 = html.fromstring(page.content)
  </code></pre>