L
L
likeab0dd32021-07-04 13:37:31
Python
likeab0dd3, 2021-07-04 13:37:31

How to make a post request?

Hello. I'm trying to make a post request to the site https://www.lamoda.ru/
I add any product to the cart, fill in all the data and look through F12 which request was sent. The only thing that works for me is the cart/ request. I look at the data that is required (headers and data) and pass them in the request. Here is the code:

import requests
from bs4 import BeautifulSoup
headers = {
    'Connection': 'keep-alive',
    'sec-ch-ua': '^\\^',
    'sec-ch-ua-mobile': '?0',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': '*/*',
    'Origin': 'https://www.lamoda.ru',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Dest': 'empty',
    'Referer': 'https://www.lamoda.ru/checkout/cart/?add=RTLAAL370001B040&popup=y',
    'Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
}

data = {
  'csrfmiddlewaretoken': 'OfWNtMQdi2pHAxVOzY6DRS8nhseZA0Ek',
  'checkout_type': 'full',
  'template_tag': 'iframe',
  'source': '',
  'timestamp': '1625394462',
  'apply_all_pup_info': '',
  'delivery_type': '',
  'initial-delivery_type': '',
  'delivery_level': '',
  'initial-delivery_level': '',
  'delivery_method': '',
  'delivery_date': '',
  'initial-delivery_date': '',
  'interval': '',
  'pickup_point': '',
  'postamat_id': '',
  'pickup_name': '',
  'postamat_name': '',
  'postamat_address': '',
  'payment_type_mask': '1',
  'lamoda_pm_field_name': 'payment_methods^%^3A1___1',
  'vk_app': '',
  'pv_uuid': '',
  'pv_code': '',
  'fingerprint': 'RGV2aWNlSWQ9MDM1OWI5NDAtYTE5ZC00NGU5LWYyNDEtM2ZhN2Y2NGU1ZTI2fHx8dXNlcl9hZ2VudD1Nb3ppbGxhLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXaW42NDsgeDY0KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTEuMC40NDcyLjEyNCBTYWZhcmkvNTM3LjM2fHx8bGFuZ3VhZ2U9cnUtUlV8fHxjb2xvcl9kZXB0aD0yNHx8fHBpeGVsX3JhdGlvPTF8fHxoYXJkd2FyZV9jb25jdXJyZW5jeT02fHx8cmVzb2x1dGlvbj0xOTIwLDEwODB8fHxhdmFpbGFibGVfcmVzb2x1dGlvbj0xOTIwLDEwNDB8fHx0aW1lem9uZV9vZmZzZXQ9LTE4MHx8fHNlc3Npb25fc3RvcmFnZT0xfHx8bG9jYWxfc3RvcmFnZT0xfHx8aW5kZXhlZF9kYj0xfHx8b3Blbl9kYXRhYmFzZT0xfHx8Y3B1X2NsYXNzPXVua25vd258fHxuYXZpZ2F0b3JfcGxhdGZvcm09V2luMzJ8fHxkb19ub3RfdHJhY2s9dW5rbm93bnx8fHJlZ3VsYXJfcGx1Z2lucz0tODk4MzIzNzQwfHx8Y2FudmFzPS00NDY3NDQyMjd8fHx3ZWJnbD0xNjM2OTQ3MzU5fHx8YWRibG9jaz1mYWxzZXx8fGhhc19saWVkX2xhbmd1YWdlcz1mYWxzZXx8fGhhc19saWVkX3Jlc29sdXRpb249ZmFsc2V8fHxoYXNfbGllZF9vcz1mYWxzZXx8fGhhc19saWVkX2Jyb3dzZXI9ZmFsc2V8fHx0b3VjaF9zdXBwb3J0PTAsZmFsc2UsZmFsc2V8fHxqc19mb250cz0tMTk0NzQyMjg5NQ^%^3D^%^3D',
  'city_id': '',
  'initial-city_id': '',
  'street_id': '',
  'initial-street_id': '',
  'building_id': '',
  'initial-building_id': '',
  'postcode': '',
  'initial-postcode': '',
  'region': '',
  'initial-region': '',
  'street': '',
  'initial-street': '',
  'house': '',
  'initial-house': '',
  'flat': '',
  'initial-flat': '',
  'latitude': '',
  'longitude': '',
  'middle_name': '',
  'affiliate_base': '',
  'affiliate_nl_not_affected': '',
  'affiliate_seo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%^D1^%^80^%^D0^%^BE^%^D0^%^BC^%^D0^%^BD^%^D0^%^B0^%^D1^%^8F',
  'first_name': 'abcd',
  'last_name': 'drgb',
  'email': 'sfdsdfsdf11^%^40gmail.com',
  'subscribed': '1',
  'customer_notes': '',
  'coupon_code': '',
  'initial-coupon_code': '',
  'payment_methods^%^3A1___1': 'PaytureVTB',
  'action': 'submit'
}

response = requests.post('https://www.lamoda.ru/checkout/cart/', headers=headers,data=data)
html=BeautifulSoup(response.text, 'lxml')
print(html)
f=open('./page11.html', 'w', encoding='UTF-8')
f.write(str(html))
f.close

I also create the html version of the site. Here is a screenshot of what it shows after sending my request:
60e18ee45e69e139472286.jpeg
I would like to know what I'm doing wrong, and how can I fulfill this request. I thought about cookies, but I don't know how to get them

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question