K
K
Kirill2020-04-23 23:20:34
Python
Kirill, 2020-04-23 23:20:34

How to correct POST request for registration?

I am trying to register on Foxford . When registering, the user packet is passed.
5ea1f76edaaa7981203302.jpeg
5ea1f729e109a388487655.jpeg
I pass them in the POST request, but I get a Response 422. My guess was that the data variable did not contain enough data. I decided to find all POST requests to the site, and added all the content to data.
Now the code looks terrible...

import requests
session = requests.session()

header = { 
  'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
  'Content-Type':'application/x-www-form-urlencoded',
  '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'
}

user = {
    'agreement': "true",
    'email': "[email protected]",
    'first_name': "ghreeeetrge",
    'last_name': "rhgefffefeg",
    'subscribed': "true",
    'type': "pupil",
    'grade_id': 4,
    'eventLabel': "20200220_13899",
    'eventType': "event",
    'eventValue': "experiment",
    'href': "https://foxford.ru/user/registration",
    'br_h': 1080,
    'br_w': 1920,
    'pageTitle': "Онлайн-школа Фоксфорд",
    'pageviewId': "301ac3af-5d33-4856-a50f-e6701f32acd8",
    'referrer': "https://foxford.ru/user/registration",
    'type': "pageview",
    'tz': "Europe/Moscow",
    'uid_ga': "GA1.2.757710269.1587670997",
    'uid_gid': "GA1.2.2080434056.1587670997",
    'uid_ym': "15876710001030451623",
    'url': "https://foxford.ru/user/registration",
    'userTs': 1587671019028,
    'ver': "v1.3.3",
    'w_h': 947,
    'w_w': 838,
    'eventCategory': "Yandex",
    'eventData': {'name': "20200220_13899", 'value': "Yandex"},
    'id': 1008034455933404,
    'ev': "Microdata",
    'dl': "https://foxford.ru/user/registration",
    'rl': "https://foxford.ru/user/registration",
    'if': "false",
    'ts': 1587671879347,
    'cd[DataLayer]': [],
    'cd[Meta]': {"title":"Онлайн-школа Фоксфорд","meta:description":"Онлайн-подготовка к ЕГЭ, ОГЭ и олимпиадам.\n    Улучшение знаний по школьным предметам с 3 по 11 класс с ведущими преподавателями","meta:keywords":"подготовка, курсы, репетитор, олимпиады, огэ, егэ, онлайн-школа фоксфорд"},
    'cd[OpenGraph]': {"og:title":"Онлайн-школа Фоксфорд","og:image":"https://s.foxford.ngcdn.ru/uploads/images/og.png","og:description":"Онлайн-подготовка к ЕГЭ, ОГЭ и олимпиадам.\n    Улучшение знаний по школьным предметам с 3 по 11 класс с ведущими преподавателями"},
    'cd[Schema.org]': [],
    'cd[JSON-LD]': [],
    'sw': 1920,
    'sh': 1080,
    'v': "2.9.16",
    'r': "stable",
    'ec': 1,
    'o': 30,
    'fbp': "fb.1.1587671005720.657309581",
    'it': 1587671878248,
    'coo': "false",
    'es': "automatic",
    'tm': 3,
    'rqm': "formPOST",
    'id': 1008034455933404,
    'ev': "SubscribedButtonClick",
    'dl': "https://foxford.ru/user/registration",
    'rl': "https://foxford.ru/user/registration",
    'if': "false",
    'ts': 1587672264722,
    'cd[buttonFeatures]': {"classList":"Button_text__1Mtef","destination":"https://foxford.ru/user/registration","id":"","imageUrl":"","innerText":"Зарегистрироваться","numChildButtons":0,"tag":"span"},
    'cd[buttonText]': "Зарегистрироваться",
    'cd[formFeatures]': [{"id":"USERS-pupil","name":"type","tag":"input","inputType":"radio"},{"id":"USERS-parent","name":"type","tag":"input","inputType":"radio"},{"id":"USERS-agent","name":"type","tag":"input","inputType":"radio"},{"id":"","name":"name","tag":"input","placeholder":"Фамилия Имя","inputType":"text","valueMeaning":"empty"},{"id":"","name":"email","tag":"input","placeholder":"Электронная почта","inputType":"email","valueMeaning":"empty"},{"id":"agreement","name":"agreement","tag":"input","inputType":"checkbox","valueMeaning":"empty"},{"id":"","name":"","tag":"button"}],
    'cd[pageFeatures]': {"title":"Онлайн-школа Фоксфорд"},
    'cd[parameters]': [{"extractorID":"2404516436325498","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{"priceCurrency":"RUB"}}},{"extractorID":"610704346341208","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{"priceCurrency":"RUB"}}},{"extractorID":"568156777309944","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{"priceCurrency":"RUB"}}},{"extractorID":"537247920456746","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{"priceCurrency":"RUB"}}},{"extractorID":"2630882250324753","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{"priceCurrency":"RUB"}}},{"extractorID":"525295031402845","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{}}},{"extractorID":"562679427614349","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{}}},{"extractorID":"560560511433712","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{}}},{"extractorID":"544120019512592","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{}}},{"extractorID":"2328730660562160","jsonLD":{"@context":"http://schema.org","@type":"Product","offers":{}}}],
    'sw': 1920,
    'sh': 1080,
    'v': "2.9.16",
    'r': "stable",
    'ec': 6,
    'o': 30,
    'fbp': "fb.1.1587671005720.657309581",
    'it': 1587671878248,
    'coo': "false",
    'es': "automatic",
    'tm': 3,
    'rqm': "formPOST",
    'Cookie': 'uid=ef1c0b7e3ccf55ff41243cfbfda141be; repeated_visit=dHJ1ZQ%3D%3D--6e52b55454ffb3e6d7ef5e5cd9bdb81c623d15ae; marketing_source_data=%7B%22utm_source%22%3A%22foxford_direct_visit%22%2C%22utm_medium%22%3A%22foxford_direct_visit%22%2C%22utm_campaign%22%3A%22foxford_direct_visit%22%2C%22utm_content%22%3A%22foxford_direct_visit%22%7D; after_sign_in_path=%2Fdashboard; _fox_session=5903bc5154a9d60f5d06b652ea7ceda3; _sid=3e6487f7bfc17023d434a397ef270cd5; _tm_lt_sid=1587670995419.957803; _tm_st_sid=1587670995419.406161; _gcl_au=1.1.1825170906.1587670996; _ga=GA1.2.757710269.1587670997; _gid=GA1.2.2080434056.1587670997; _dc_gtm_UA-35041074-2=1; _gat_UA-35041074-29=1; _gat_UA-35041074-2=1; tmr_lvid=fb9e2be4d09db4d27b6bac0a92ff248f; tmr_lvidTS=1587670997976; _ym_uid=15876710001030451623; _ym_d=1587671000; _ym_isad=2; _ym_visorc_1508995=w; _foxford_cookie_consent=yes; _gu=3bb43c67-0ae3-40dd-aa1e-0a1ce64b5caf; _fbp=fb.1.1587671005720.657309581; csrf_token=SyvvowAqLZKlKEKIzjh8fUkWqUgc8ElGZ/jP9p3rbERmFdXLgyGsnI5gDFZxN52ZWJXQlH6l7kCWxSprd1Um8g==; _gs=2.s(src%3Dhttps%3A%2F%2Ffoxford.ru%2Fuser%2Fregistration)c%5BDesktop%2CChrome%2C96%3A287%3A3813%3A%2CWindows%2C176.59.53.202%5D; _gw=2.u%5B%2C%2C%2C%2C%5Dv%5B~fr5kv%2C~2%2C~0%5Da(); tmr_detect=0%7C1587671012890; tmr_reqNum=4; _mkra_stck=38f0740246fba8df6a3418ee991dcc7f%3A1587671022.654571'
}

session.post('https://www.facebook.com/tr/', data=user)
response = session.post('https://foxford.ru/user', data=user)
print(response)

I don't understand what the problem is... I'm trying to make requests in a row, it's still 422.
Maybe I made the request incorrectly and I need to send something else? Help and do not judge strictly =)
PS. FOR THOSE WHO DO NOT UNDERSTAND THE QUESTION
import requests
session = requests.session()

header = { 
  'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
  'Content-Type':'application/x-www-form-urlencoded',
  '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'
}

user = {
    'agreement': "true", 
    'email': "[email protected]",
    'first_name': "ghreeeetrge",
    'last_name': "rhgefffefeg",
    'subscribed': "true",
    'type': "pupil"
} #Даже если вместо "true" поставить True

response = session.post('https://foxford.ru/user', data=user)
print(response)

This code throws a Response 422!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
veleus, 2020-04-23
@veleus

Why do you need so many arguments, can you pass 6 arguments for registration?

A
Andrey_Dolg, 2020-04-26
@Andrey_Dolg

I'm wondering why you are so prepared and write the correct headers but do not use it?
Well, in general, 422 means that the regular expression for one of the fields could not process the value, as I understand it.
It is quite possible that you end up in some left handler due to a crooked request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question