[英]Trying to send post request with python but doesnt work
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:我有这个从 burp 套件中截获的请求,我正在尝试使用 python 脚本将其自动化,以发送相同的发布请求,我复制了所有参数和标题,但它没有运行并显示很多错误,这是我的代码:
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:从您的错误中调用检查您的标题['Content-Length'],您可以尝试将其更改为 Int 类型,如下所示:
"Content-Length": "165",
and becareful with your object r at your print() function you still not declare it to be request so you can print() like this:小心你的 object r 在你的 print() function 你仍然没有声明它是 request 所以你可以像这样 print() :
print(request.status_code, request.reason)
in you last line in your code.在你代码的最后一行。
Feel free to comments me.随意评论我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.