A
A
alex stephen2015-04-02 16:20:56
Python
alex stephen, 2015-04-02 16:20:56

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)

upd: I tried to disable JS in the browser, but the form is sent without it, i.e. the problem is in another

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2015-04-02
@berezuev

Send to httpbin.org/post
this is a service for debugging such requests, see what comes up.
Then it will be clear on which side the problem is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question