Answer the question
In order to leave comments, you need to log in
Python Requests submitting a form post request?
There is a simple bootstrap3 form with a post request, jquery validation (something like this is generated by yii2).
I am writing a script in python that, using the Requests library, will log in and submit the form. I go through authorization, I get a CSRF token, everywhere in the headers the 200th code (success), however, after submitting the form, a page is returned claiming that I sent empty fields. I send all the necessary fields and the csrf token in the "data" attribute (I looked at the list of fields in chrome dev tools), but it seems that the server does not accept them.
What can be a jamb?
I can't post a link to the form. Just a snippet of code
#сначала идет авторизация, затем из страницы, на которую нас перебросило с формы, вытаскивается csrf токен
url='https://example.com/form'
payload = {
'lastName': 'Обама',
'firstName': 'Барак',
'middleName': 'Хусейн',
'birthdate': '04/08/1961',
'_csrf': csrf
}
headers= {
'Content-type': 'charset=utf-8', 'X-CSRF-TOKEN': csrf}
s.headers.update({'Connection': 'keep-alive', "Referer": url})
r4=s.post(url, data=payload, headers=headers)
w = open("dump.html", "wb")
w.write(r4.text.encode("utf-8"))
w.close()
print(r4.text.encode("utf-8"))
print(r4.url)
print(r4.headers)
print(r4)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question