0

So, I've imported a curl (bash) from Chrome developer tools to Postman, being the curl import as follows

curl 'https://spectate-web.888sport.es/spectate/load/state' \
  -H 'authority: spectate-web.888sport.es' \
  -H 'cache-control: max-age=0' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Safari/537.36' \
  -H 'newrelic: eyJ2IjpbMCwxXSwiZCI6eyJ0eSI6IkJyb3dzZXIiLCJhYyI6IjI1MDk2NzQiLCJhcCI6IjMwNzYyODM3IiwiaWQiOiJhOTczNGMyNjE1ZjFmNjk4IiwidHIiOiI4ZTljMmY2Y2UyYjY0YjVmIiwidGkiOjE2NDQ4NjA2NDAyMzZ9fQ==' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary90I8BBa9QQhaKZgx' \
  -H 'accept: */*' \
  -H 'sec-gpc: 1' \
  -H 'origin: https://www.888sport.es' \
  -H 'sec-fetch-site: same-site' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-dest: empty' \
  -H 'referer: https://www.888sport.es/' \
  -H 'accept-language: es-ES,es;q=0.9' \
  -H 'cookie: 888Cookie=lang%3Des%26OSR%3D485697%26RefType%3DNoReferrer%26TestData%3D%7B%22country%22%3A%22esp%22%2C%22orig-lp%22%3A%22https%3A%2F%2Fwww.888sport.es%2F%22%2C%22referrer%22%3A%22NULL%22%7D' \
  --data-raw $'------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="currency_code"\r\n\r\nEUR\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="language"\r\n\r\nesp\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="sub_brand_id"\r\n\r\n110\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="brand_id"\r\n\r\n58\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="regulation_type_id"\r\n\r\n2\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="timezone"\r\n\r\n-1\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="browsing_country_code"\r\n\r\nESP\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="product_package_id"\r\n\r\n112\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="user_mode"\r\n\r\nAnonymous\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx\r\nContent-Disposition: form-data; name="spectate_timezone"\r\n\r\nEurope/Madrid\r\n------WebKitFormBoundary90I8BBa9QQhaKZgx--\r\n' \
  --compressed

This works perfectly,but when I try to run it on Python like this

import requests
payload={'currency_code': 'EUR',
 'language': 'esp',
 'sub_brand_id': '110',
 'brand_id': '58',
 'regulation_type_id': '2',
 'timezone': '-1',
 'browsing_country_code': 'ESP',
 'product_package_id': '112',
 'user_mode': 'Anonymous',
 'spectate_timezone': 'Europe/Madrid'}

headers={'authority': 'spectate-web.888sport.es',
 'cache-control': 'max-age=0',
 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Safari/537.36',
 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary90I8BBa9QQhaKZgx',
 'accept': '*/*',
 'sec-gpc': '1',
 'origin': 'https://www.888sport.es',
 'sec-fetch-site': 'same-site',
 'sec-fetch-mode': 'cors',
 'sec-fetch-dest': 'empty',
 'referer': 'https://www.888sport.es/',
 'accept-language': 'es-ES,es;q=0.9',
 'cookie': '888Cookie=lang%3Des%26OSR%3D485697%26RefType%3DNoReferrer%26TestData%3D%7B%22country%22%3A%22esp%22%2C%22orig-lp%22%3A%22https%3A%2F%2Fwww.888sport.es%2F%22%2C%22referrer%22%3A%22NULL%22%7D; anon_hash=e9910ad734f8d0c19c0ea9c2e43681ad; bbsess=BCceFW8B5waVeLa%2CvJWQDCs7bz5; lang=esp; odds_format=DECIMAL; spectate_session=37190118-140b-4b69-8ad9-c4d8e86e85e9%3Aanon'}

response=requests.post(url=url,headers=headers,data=payload)

This is what I get

response.content
b'"[EMPTY_POST_DATA]"'

I've tried with data=payload, with json=payload and with data=json.dumps(payload)

All three options returned the same. My question is, how do I make it work? Why does it work on Postman but not on Python?

puppet
  • 585
  • 1
  • 10
  • 29
  • Does this answer your question? [How to send a "multipart/form-data" with requests in python?](https://stackoverflow.com/questions/12385179/how-to-send-a-multipart-form-data-with-requests-in-python) – Crowman Feb 14 '22 at 22:02

0 Answers0