using urlencode for credentials to pass on post method python

Viewed 19

I have been trying to pass urlencode for credentials and can get the credentials as it is but facing the problem in request.post method where it always show

File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:"urlname"/auth/login?username=user&password=password

can someone suggest what am I doing wrong here.

    loginin["password"] = PASSWORD
    loginin = {"username": USER, "password":PASSWORD}
    logindata = urllib.parse.urlencode(loginin, safe='[_/+$')
    print(type(logindata), logindata)
  if debug:
    print(logindata)
  headers = {'content-type': 'application/json'}
  rlogin = requests.post(urllogin, params=logindata, headers=headers, verify=False)
  rlogin.raise_for_status()
  print("status_code:", rlogin.status_code)
  if rlogin.status_code == 200:
    resplogin = json.loads(rlogin.text)
    print("resplogin",resplogin)
0 Answers
Related