title: I am trying to simulate a user login to Chegg but I am met with an access denied page
body: <p>I believe it may have something to do with the headers I have. Maybe I need to include more? Any help is greatly appreciated.</p>
  <p>For those curious, I am doing this in order to get a Chegg answer by combining this code with the discord API.</p>
  <p>Steps to reproduce:</p>
  <ol>
  <li>Create a Chegg account</li>
  <li>While logged out, go to inspect element to access the developer console in a web browser</li>
  <li>go to the network tab in the console</li>
  <li>Go to the Chegg login page with the console open</li>
  <li>In the network tab, find the login documentby choosing document type as XHR and searching for 'auth'</li>
  <li>Go to the request section to see the headers.</li>
  <li>Go to the very bottom to see the form data.</li>
  </ol>
  <p>My current code in python:</p>
  <pre><code>from bs4 import BeautifulSoup as bs
  import requests
  
  EMAIL = config.USR
  PASSWORD = config.PSWRD
  
  URL = 'https://www.chegg.com/'
  LOGIN_ROUTE = 'auth?action=login&amp;redirect=https%3A%2F%2Fwww.chegg.com%2F'
  
  HEADERS = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', 'origin': URL, 'referer': URL + LOGIN_ROUTE, 'Connection': 'keep-alive'}
  
  s = requests.session()
  
  login_payload = {
          'email': EMAIL,
          'password': PASSWORD, 
          }
  
  login_req = s.post(URL + LOGIN_ROUTE, headers=HEADERS, data=login_payload)
  
  print(login_req.status_code)
  
  cookies = login_req.cookies
  
  soup = bs(s.get(URL).text, 'html.parser')
  
  answer='answer.html'
  with open(answer, &quot;w&quot;) as file:
      file.write(str(soup))
  
  </code></pre>
  <p>The HTML output:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"/&gt;
  &lt;meta content="width=device-width, initial-scale=1" name="viewport"/&gt;
  &lt;title&gt;Access to this page has been denied.&lt;/title&gt;
  &lt;link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"/&gt;
  &lt;style&gt;
          html, body {
              margin: 0;
              padding: 0;
              font-family: 'Open Sans', sans-serif;
              color: #000;
          }
  
          a {
              color: #c5c5c5;
              text-decoration: none;
          }
  
          .container {
              align-items: center;
              display: flex;
              flex: 1;
              justify-content: space-between;
              flex-direction: column;
              height: 100%;
          }
  
          .container &gt; div {
              width: 100%;
              display: flex;
              justify-content: center;
          }
  
          .container &gt; div &gt; div {
              display: flex;
              width: 80%;
          }
  
          .customer-logo-wrapper {
              padding-top: 2rem;
              flex-grow: 0;
              background-color: #fff;
              visibility: hidden;
          }
  
          .customer-logo {
              border-bottom: 1px solid #000;
          }
  
          .customer-logo &gt; img {
              padding-bottom: 1rem;
              max-height: 50px;
              max-width: 100%;
          }
  
          .page-title-wrapper {
              flex-grow: 2;
          }
  
          .page-title {
              flex-direction: column-reverse;
          }
  
          .content-wrapper {
              flex-grow: 5;
          }
  
          .content {
              flex-direction: column;
          }
  
          .page-footer-wrapper {
              align-items: center;
              flex-grow: 0.2;
              background-color: #000;
              color: #c5c5c5;
              font-size: 70%;
          }
  
          @media (min-width: 768px) {
              html, body {
                  height: 100%;
              }
          }
      &lt;/style&gt;
  &lt;!-- Custom CSS --&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;section class="container"&gt;
  &lt;div class="customer-logo-wrapper"&gt;
  &lt;div class="customer-logo"&gt;
  &lt;img alt="Logo" src=""/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="page-title-wrapper"&gt;
  &lt;div class="page-title"&gt;
  &lt;h1&gt;Please verify you are a human&lt;/h1&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="content-wrapper"&gt;
  &lt;div class="content"&gt;
  &lt;div id="px-captcha"&gt;
  &lt;/div&gt;
  &lt;p&gt;
                  Access to this page has been denied because we believe you are using automation tools to browse the
                  website.
              &lt;/p&gt;
  &lt;p&gt;
                  This may happen as a result of the following:
              &lt;/p&gt;
  &lt;ul&gt;
  &lt;li&gt;
                      Javascript is disabled or blocked by an extension (ad blockers for example)
                  &lt;/li&gt;
  &lt;li&gt;
                      Your browser does not support cookies
                  &lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;
                  Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking
                  them from loading.
              &lt;/p&gt;
  &lt;p&gt;
                  Reference ID: #6a688650-086b-11eb-9f07-b303a8506d58
              &lt;/p&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="page-footer-wrapper"&gt;
  &lt;div class="page-footer"&gt;
  &lt;p&gt;
                  Powered by
                  &lt;a href="https://www.perimeterx.com/whywasiblocked"&gt;PerimeterX&lt;/a&gt;
                  , Inc.
              &lt;/p&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/section&gt;
  &lt;!-- Px --&gt;
  &lt;script&gt;
      window._pxAppId = 'PXzYvFOXaC';
      window._pxJsClientSrc = '//client.perimeterx.net/PXzYvFOXaC/main.min.js';
      window._pxFirstPartyEnabled = false;
      window._pxVid = '';
      window._pxUuid = '6a688650-086b-11eb-9f07-b303a8506d58';
      window._pxHostUrl = 'https://collector-PXzYvFOXaC.perimeterx.net';
  &lt;/script&gt;
  &lt;script&gt;
      var s = document.createElement('script');
      s.src = '//captcha.px-cdn.net/PXzYvFOXaC/captcha.js?a=c&amp;u=6a688650-086b-11eb-9f07-b303a8506d58&amp;v=&amp;m=0';
      var p = document.getElementsByTagName('head')[0];
      p.insertBefore(s, null);
      if (false) {
          s.onerror = function () {
              s = document.createElement('script');
              var suffixIndex = '//captcha.px-cdn.net/PXzYvFOXaC/captcha.js?a=c&amp;u=6a688650-086b-11eb-9f07-b303a8506d58&amp;v=&amp;m=0'.indexOf('captcha.js');
              var temperedBlockScript = '//captcha.px-cdn.net/PXzYvFOXaC/captcha.js?a=c&amp;u=6a688650-086b-11eb-9f07-b303a8506d58&amp;v=&amp;m=0'.substring(suffixIndex);
              s.src = '//captcha.px-cdn.net/PXzYvFOXaC/' + temperedBlockScript;
              p.parentNode.insertBefore(s, p);
          };
      }
  &lt;/script&gt;
  &lt;!-- Custom Script --&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>