title: Python requests with login credentials
body: <p>I am trying to login to a URL &amp; download the content then parse, the URL needs username &amp; password to login.</p>
  
  <p>using below gives below errors:</p>
  
  <pre><code>import requests
  url = 'https://test/acx/databaseUsage.jssp?object=all'
  values = {'username': 'test_user',
            'password': 'test_pswd'}
  headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
  
  r = requests.post(url, data=values, headers=headers)
  print r.content
  </code></pre>
  
  <p>Error log output from above code:</p>
  
  <p>tried with below values as well , without any success</p>
  
  <p>values = {'Login': 'test',
            'Password': 'test',
            'Log in': 'submit'}</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=Edge"/&gt; &lt;!-- must be first; see SD5930 --&gt;
      &lt;title&gt;Test URL login&lt;/title&gt;
      &lt;!--meta name="apple-mobile-web-app-capable" content="yes" /--&gt;
      &lt;link type="text/css" rel="StyleSheet" href="/nl/logon.css"&gt;&lt;/link&gt;
    &lt;/head&gt;
    &lt;body onLoad="setFocus();"&gt;
      &lt;div id="htmlContent"&gt;
        &lt;div id="container"&gt;
          &lt;div id="content"&gt;
            &lt;div class="login_frame"&gt;
              &lt;div class="header_login"&gt;
                &lt;img src="/nl/img/logo.png" alt="Test URL" /&gt;
              &lt;/div&gt;
              &lt;div id="form-main"&gt;
                &lt;!--[if lte IE 7]&gt;
                &lt;div class="warning"&gt;&lt;b&gt;Warning&lt;/b&gt;: your browser isn't supported by Test URL. &lt;br/&gt;To be able to use Test URL to its full potential, you need to update your browser.&lt;/div&gt;
                &lt;![endif]--&gt;
                &lt;form method="POST" autocorrect="off" autocapitalize="off" name="loginForm" action="/nl/jsp/logon.jsp"&gt;
                  &lt;input type="hidden" name="action" value="submit" /&gt;
  
                  &lt;input type="hidden" name="target" value="/acx/databaseUsage.jssp?object=all"&gt;
  
                  &lt;p class="input first"&gt;
                    &lt;label for="login"&gt;Login&lt;/label&gt;
                    &lt;span&gt;
                      &lt;input id="login" name="login" tabindex="1" type="text" value="" /&gt;
                    &lt;/span&gt;
                  &lt;/p&gt;
                  &lt;p class="input"&gt;
                    &lt;label for="password"&gt;Password&lt;/label&gt;
                    &lt;span&gt;
                      &lt;input id="password" name="password" tabindex="2" type="password" autocomplete="off" /&gt;
                    &lt;/span&gt;
                    &lt;br /&gt;
                  &lt;/p&gt;
                  &lt;p class="memorize submit last"&gt;
  
                      &lt;input id="rememberMe" name="rememberMe" class="checkbox" tabindex="3" type="checkbox" /&gt;
                      &lt;label class="checkbox" for="rememberMe"&gt;Keep me logged in&lt;/label&gt;
  
                    &lt;button id="validate" type="submit"&gt;Log in&lt;/button&gt;
                  &lt;/p&gt;
                &lt;/form&gt;
              &lt;/div&gt;
  
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
  
        &lt;div id="footer" class="dashboardFooter"&gt;
          &lt;div id="footerContent" class="nlui-pageWidth"&gt;
            &lt;p&gt;
            &amp;copy; Test URL 2017
            &lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
      &lt;/div&gt;
      &lt;script type="text/javascript"&gt;
        function setFocus() {
          document.loginForm.login.focus();
        }
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Image of login page</p>
  
  <p><a href="https://i.stack.imgur.com/DMCE8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DMCE8.png" alt="enter image description here"></a></p>