i have this request that i intercepted from burp suite, and i am trying to automate it with a python script to send the same post request i copied all the paramaters and headerse, but it doesnt run and shows many errors, this is my code:
import json
import requests
headers = {
"Host": "zefoy.com",
"Connection": "close",
"Content-Length": 165,
"sec-ch-ua": " 'Not A;Brand';v='99', 'Chromium';v='90', 'Google Chrome';v='90' ",
"X-Requested-With": "MLHttpRequest",
"sec-ch-ua-mobile": "0",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryHEOJpHz1H6CQRzKM",
"Origin": "https://zefoy.com",
"Sec-Fetch-Site": "Sec-Fetch-Site: ",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en,ar;q=0.9,en-US;q=0.8"
}
data = " Cookie: __cfduid=d48c779b0ee1d5130af491e8a4229cb2d1619994598; PHPSESSID=fvf4tb72c2kifr5bcej2kpv932 ------WebKitFormBoundaryHEOJpHz1H6CQRzKM Content-Disposition: form-data; name='bf16968c49853c3' 6958925981625158913 ------WebKitFormBoundaryHEOJpHz1H6CQRzKM-- "
url = "http://zefoy.com/c2VuZC9mb2xsb3dlcnNfdGlrdG9V"
request = requests.post(url, headers=headers, data=data)
print(r.status_code, r.reason)
it shows errors such:
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\Ahmed\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Ahmed\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "C:\Users\Ahmed\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "C:\Users\Ahmed\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\models.py", line 317, in prepare
self.prepare_headers(headers)
File "C:\Users\Ahmed\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\models.py", line 451, in prepare_headers
check_header_validity(header)
File "C:\Users\Ahmed\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\utils.py", line 959, in check_header_validity
raise InvalidHeader("Value for header {%s: %s} must be of type str or "
requests.exceptions.InvalidHeader: Value for header {Content-Length: 165} must be of type str or bytes, not <class 'int'>
From your Error is called for check your headers['Content-Length'] you can try to change it to Int type like this:
and becareful with your object r at your print() function you still not declare it to be request so you can print() like this:
in you last line in your code.
Feel free to comments me.