How to send Request Payload using the Requests library?

Need to automate getting referral links with site. When getting links manually, the browser sends a post request with a Payload part: aa63ce0604df4b4e879cd794ffa6fdd9

Try also to spend such a request:

def getUrl(login, password, link):
 with requests.Session() as session:
 data = dict(username=login, password=password, remember=1, check_ip=0)
 url = session.get('https://epn.bz')
 login = session.post('https://epn.bz/ru/auth/login', data=data, cookies=url.cookies)
 cabinet = session.get('https://epn.bz/ru/cabinet/', cookies=login.cookies)
 payload = {'all_banners': False,
 'attract_to_cashback': False,
 'cookie_time': "30days",
 'desc': 'group',
 'expiration_time': ",
 'format': '1',
 'image': ",
 'isAllow': 0,
 'lang': 'EN',
 'link': link,
 'no_affiliate_direct': True,
 'offer_type': 'ali',
 'rejectChange': False,
 'selected_banners': [],
 'size': None}
 create = session.post('https://epn.bz/ru/creative/create', data=payload, cookies=cabinet.cookies)
 print(create.text)


But in response we get: {"success":0,"message":"not_aliexpress"}
However, the link to the site Ali passed exactly the same as when sending the request manually through the browser.

Properly convey Payload part?
August 19th 19 at 23:12
3 answers
August 19th 19 at 23:14
Solution
Read and view in the browser Request Headers. Most likely you need to spoof the HTTP_REFERER.
August 19th 19 at 23:16
Solution
explicitly pass cookies in queries is optional, since the Session object() does this for you.
judging by the design payload of your browser, it can be assumed that it is sent in json format, while you are sending it in the format x-www-form-urlencoded.
Try session.post('https://epn.bz/ru/creative/create', data=json.dumps(payload))
didn't help, but thanks, I think it is closer to the solution - keanu commented on August 19th 19 at 23:19
August 19th 19 at 23:18
The problem was in the uploaded headers in json format payload part, it's done
Can you tell us more? Show as sold? - keanu commented on August 19th 19 at 23:21
I donĂ­t remember now, but it seems data=payload replaced json=payload - Alford.Mohr commented on August 19th 19 at 23:24
and all? with headers does not work? - keanu commented on August 19th 19 at 23:27
, replace json=payload didn't work)) - Alford.Mohr commented on August 19th 19 at 23:30
unfortunately I can't find this project. And what is the response returned from the server? - Alford.Mohr commented on August 19th 19 at 23:33
same: {"success":0,"message":"not_aliexpress"} - keanu commented on August 19th 19 at 23:36

Find more questions by tags ParsingPython