minio / minio-py

MinIO Client SDK for Python
https://docs.min.io/docs/python-client-quickstart-guide.html
Apache License 2.0
822 stars 318 forks source link

User metadata are not accurately parsed in list_objects response #1396

Closed renaudcalmont closed 7 months ago

renaudcalmont commented 7 months ago

Hi, I found a previous attempt to fix this issue, that was reverted https://github.com/minio/minio-py/pull/1240

The issue remains... if you expect to include the user metadata in the list_object response using the include_user_meta parameter as described in the documentation https://min.io/docs/minio/linux/developers/python/API.html#list_objects the response will only yield (JSONified): "_metadata": { "Items": "" } despite the data being actually present in the XML response of the server.

balamurugana commented 7 months ago

It works as expected with play.min.io. Please check your server.

$ PYTHONPATH=$PWD python
>>> from minio import Minio
>>> import sys
>>> c = Minio("play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
>>> c.trace_on(sys.stdout)
>>> objects = c.list_objects("mybucket")
>>> for obj in objects:
...     print(obj)
...     print(obj.metadata)
>>> objects = c.list_objects("mybucket", include_user_meta=True)
>>> for obj in objects:
...     print(obj)
...     print(obj.metadata)
... 
---------START-HTTP---------
GET /mybucket?delimiter=%2F&encoding-type=url&list-type=2&max-keys=1000&metadata=true&prefix= HTTP/1.1
Host: play.min.io
User-Agent: MinIO (Linux; x86_64) minio-py/7.2.5
X-Amz-Content-Sha256: UNSIGNED-PAYLOAD
X-Amz-Date: 20240222T020918Z
Authorization: AWS4-HMAC-SHA256 Credential=*REDACTED*/20240222/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=*REDACTED*

HTTP/1.1 200
Server: nginx/1.18.0 (Ubuntu)
Date: Thu, 22 Feb 2024 02:09:18 GMT
Content-Type: application/xml
Content-Length: 699
Connection: keep-alive
Accept-Ranges: bytes
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Origin
Vary: Accept-Encoding
X-Amz-Bucket-Region: us-east-1
X-Amz-Id-2: 3e996b2f640d7e065d3a5c4e39a5538cefb82e3e77771990265e4698d8681eac
X-Amz-Request-Id: 17B60D5309AE546A
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block

<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>mybucket</Name><Prefix></Prefix><KeyCount>1</KeyCount><MaxKeys>1000</MaxKeys><Delimiter>/</Delimiter><IsTruncated>false</IsTruncated><Contents><Key>70E27C66-C79E-4941-9457-6D9D220133A6.jpeg</Key><LastModified>2024-02-20T15:27:25.518Z</LastModified><ETag>&#34;7e8007c156cf149f8524fc65e16499f8&#34;</ETag><Size>843386</Size><StorageClass>STANDARD</StorageClass><UserMetadata><content-type>application/octet-stream</content-type><expires>Mon, 01 Jan 0001 00:00:00 GMT</expires></UserMetadata><Internal><K>2</K><M>2</M></Internal></Contents><EncodingType>url</EncodingType></ListBucketResult>
----------END-HTTP----------
<minio.datatypes.Object object at 0x7fae7d001340>
{'content-type': 'application/octet-stream', 'expires': 'Mon, 01 Jan 0001 00:00:00 GMT'}
>>>