0

I am trying to login to a website by using Python script. Please help me

url = 'http://12.345.67.891:8000/login'
values = {'username': 'abcdefg',
          'password': 'apple'}

r = requests.post(url, data=values)
print r.content

Getting below error when executed the code

[{"fieldNames":["User"],"classification":"RequiredError","message":"Required"}]
SG131712
  • 135
  • 3
  • 13

1 Answers1

3

Perhaps it is expecting User not username:

url = 'http://12.345.67.891:8000/login'
values = {'User': 'abcdefg',
          'password': 'apple'}

r = requests.post(url, data=values)
print(r.content)
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
  • 1
    I believe the "U" is supposed to be uppercase as it reads in their error. `"User"` – Jab Feb 15 '19 at 10:36
  • @Jaba over-speeding, fixed! :D – DirtyBit Feb 15 '19 at 10:37
  • 1
    By implementing the above code i am getting output as "{"message":"Logged in"}". Does that mean it is logged in? – SG131712 Feb 15 '19 at 10:38
  • @SwethaGorantla indeed, it does! – DirtyBit Feb 15 '19 at 10:39
  • Thanks, when i manually browse through the website. Once i logged in it is redirecting to a page which is homepage. In that home page response i can see cookies available which we can use in the further requests. an you please help me to find how to store cookies in a variable from the response of the login page and use it in further requests? – SG131712 Feb 15 '19 at 10:48
  • @SwethaGorantla Indeed, but that is quiet a different question, you can ask another question with the details and consider this one marked if it helped, cheers. – DirtyBit Feb 15 '19 at 10:57