1

Im trying to scrape the web, but as a output getting an error with AADSTS165000: Invalid Request.

My Python code is pretty simple:

import requests
s = requests.session()
link = 'https://login.microsoftonline.com/.../login'
email = {'loginfmt':'...',
             'passwd':'...',}
loging = s.post(link, data = email)

f = open('123.txt', 'w')
f.write(loging.text)
f.close()

But getting html output wiht The request did not return all of the form fields. Failure Reasons:[Missing session context cookie;Token was not provided;]

How can I emulate all the requirements to sucessefully loggin in and get the html?

Leonid-98
  • 71
  • 6
  • [This](https://stackoverflow.com/questions/25091976/python-requests-get-cookies) may answer your question. It address how to get session cookies using `requests`. – James Tollefson Nov 06 '20 at 01:12

2 Answers2

0

To inject cookies into your request, you need to have the cookies ready,

assuming you have that already,

cookies = {"key":"value"}
loging = s.post(link, data = email, cookies=cookies)
kennysliding
  • 2,783
  • 1
  • 10
  • 31
0

You probably need to grab the session cookies after logging in, and send it with your next request.

So do

cookies = s.cookies.get_dict()
loging = s.post(link, data = email, cookies=cookies)
isopach
  • 1,783
  • 7
  • 31
  • 43