How to create a post request using python?

Are on site, trained to parse.

When entering data in the main input or submit and send the request in js it looks like this:

await fetch("https://www.work.ua/_data/_ajax/by-category-block.php", {
 "credentials": "include"
 "headers": {
 "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0",
 "Accept": "*/*",
 "Accept-Language": "EN-us,EN;q=0.8,en-US;q=0.5,en;q=0.3",
 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
 "X-Requested-With": "XMLHttpRequest"
},
 "referrer": "https://www.work.ua/ru/jobs/by-category/",
 "body": "region_id=0&search_type=jobs",
 "method": "POST",
 "mode": "cors"
});


The query runs and returns data.

Trying to implement in python

import requests

data = """{"credentials": "include","headers": {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0","Accept": "*/*","Accept-Language": "EN-us,EN;q=0.8,en-US;q=0.5,en;q=0.3","Content-Type": "application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With": "XMLHttpRequest"},"referrer": "https://www.work.ua/ru/jobs/by-category/","body": "region_id=0&search_type=jobs","method": "POST","mode": "cors"} """

url = "https://www.work.ua/_data/_ajax/by-category-block.php"

r = requests.post(url , data ) 

print(r.text)


The text is not observed. Sure I'm naive, but prompt in what side to dig?
April 3rd 20 at 18:49
2 answers
April 3rd 20 at 18:51
Solution
You really don't use libo requests. Should be something like this:

import requests

url = "https://www.work.ua/_data/_ajax/by-category-block.php"
headers = {
 "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0",
 "Accept": "*/*","Accept-Language": "EN-us,EN;q=0.8,en-US;q=0.5,en;q=0.3",
 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
 "X-Requested-With": "XMLHttpRequest"
}
data = "region_id=0&search_type=jobs"

r = requests.post(url=url, headers=headers , data=data)

print(r.text)
In General, and here I believe the excess headers, etc. but just copied from your question dictionary. - karelle_Feest commented on April 3rd 20 at 18:54
Works, thank you very much(happy). - Dereck.Hermist commented on April 3rd 20 at 18:57
@Dereck.Hermist, not for that - karelle_Feest commented on April 3rd 20 at 19:00
April 3rd 20 at 18:53
You in data, which must be a dictionary shoved the LINE!!!
People, don't be lazy, read at least a hundred pages about the language before it to write something!!!
At least basic stuff!!!

Find more questions by tags AJAXPython