I found the code for authorization, it seems to work:

import lxml.html import requests login = 'логин' password = 'пароль' url = 'https://vk.com/' headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20100101 Firefox/14.0.1', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language':'ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3', 'Accept-Encoding':'gzip, deflate', 'Connection':'keep-alive', 'DNT':'1' } session = requests.session() data = session.get(url, headers=headers).content page = lxml.html.fromstring(data) form = page.forms[0] form.fields['email'] = login form.fields['pass'] = password response = session.post(form.action, data=form.form_values()) print(response.text) 

Help me figure out how to see in the future which post requests are sent from the site, and how to catch them, in order to transfer them to python.

PS Did as user Mr Morgan spoke and got these values

 act:a_send al:1 gid:0 guid:151773532908381 hash:1517735163_cd46fbd56673503461 im_v:2 media: msg: test message random_id:626404632 to: id того, кому я писал 

Further Mr Morgan wrote

You will see the values ​​of variables, they need to be specified as a dictionary (similar to headers), but passed as data.

But the variables guid , hash and random_id constantly changing, how to form them?

    1 answer 1

    Google chrome

    F12 -> Network tab -> make the browser send the form (press the войти button or similar) -> press the red button (stop record) -> view the requests you have caught.

    In other browsers, you need to find a developer panel and do the same.


    You will see the values ​​of variables, they need to be specified as a dictionary (similar to headers), but passed as data.

     session.post(..., data={...}) 
    • Did as you said, got a set of variables. Among them there are three that are constantly changing: guid , hash and random_id . Tell me how to generate them. - relevant
    • It depends on the site. - Mr Morgan
    • please explain. In what sense, "it depends on the site"? I need only VC. - relevant
    • Then look by analogy with github.com/python273/vk_api/blob/master/vk_api/audio.py - Mr Morgan
    • your example is not appropriate, there is not a word about what I asked. Quote: "Among them there are three that are constantly changing: guid , hash and random_id . Tell random_id how to generate them." - relevant