Why do I get 401 Status code from post request?

2019-08-25 20:47发布

问题:

I am trying to login to a website using python requests library, but keep getting a 401 status code.

I have tried many variations of the various post function variables including:

  • data = formData, form data includes the correct username, password and _csrf token

  • data = json.dumps(formData)

  • headers = headers (which included the "user-agent" and many other fields)

  • auth = HTTPBasicAuth(username,password) where username and password are the correct string variables for the site login

with requests.Session() as c:
    loginPage = c.get(LoginURL)
    loggedInPage = c.post(LoginURL, 
                          data=formData,
                          headers=headers,
                          auth=HTTPBasicAuth(username,password)
                    )