Не могу сделать POST запросы в MinIO
Не могу никак сделать сохранение файла в MinIO через presigned_url
. Есть скрипт:
import minio
client = minio.Minio(
endpoint="10.242.223.170:9005",
access_key=r"",
secret_key=r"",
secure=False
)
url = client.get_presigned_url(
method="POST",
bucket_name="public-dev",
object_name="commands.txt"
)
print(url)
file = {'upload_file': ('commands.txt', open(r'D:\commands.txt', 'rb')),}
r = requests.post(url, files=file, headers={'Content-Type': 'text/plain'})
print(r.request.url)
print(r.request.headers)
print(r.request)
print("-" * 30)
print(r.status_code)
print(r.headers)
print(r.text)
Выводит:
http://10.242.223.170:9005/public-dev/commands.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=raeEpdF2rKosEiX5WkXF%2F20240306%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240306T194904Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=75546e186dc7396b8b15f65dfc4ba75db89fa50ce29de94185812d291a12336f
http://10.242.223.170:9005/public-dev/commands.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=raeEpdF2rKosEiX5WkXF%2F20240306%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240306T194904Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=75546e186dc7396b8b15f65dfc4ba75db89fa50ce29de94185812d291a12336f
{'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate, zstd', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'text/plain', 'Content-Length': '446'}
<PreparedRequest [POST]>
------------------------------
400
{'Accept-Ranges': 'bytes', 'Content-Length': '271', 'Content-Type': 'application/xml', 'Server': 'MinIO', 'Vary': 'Origin', 'Date': 'Wed, 06 Mar 2024 19:49:04 GMT'}
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>BadRequest</Code><Message>An error occurred when parsing the HTTP request POST at '/public-dev/commands.txt'</Message><Resource>/public-dev/commands.txt</Resource><RequestId></RequestId><HostId></HostId></Error>
Сначала думал, что ошибка в скрипте, запустил эту же ссылку в Postman.
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>BadRequest</Code>
<Message>An error occurred when parsing the HTTP request POST at '/public-dev/commands.txt'</Message>
<Resource>/public-dev/commands.txt</Resource>
<RequestId></RequestId>
<HostId></HostId>
</Error>
При этом, что браузер, что аналогичный скрипт, что Postman спокойно обрабатывают такую же ссылку, только на GET.