Skip to content

Commit 84e57b6

Browse files
miso-belicaharshavardhana
authored andcommitted
Remove white-space characters before parsing XML (#792)
Minio sometimes responds with newlines before the XML declaration. The `data` variable holds something like `b'\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r<?xml version="1.0" encoding="UTF-8"?>\n<CompleteMultipartUploadResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Location>https://minio-api.example.com/storage/data.csv.gz</Location><Bucket>storage</Bucket><Key>data.csv.gz</Key><ETag>7c913063d32676ebb4356e68db88db20-3</ETag></Co...'` and lxml can't parse such response with error `InvalidXMLError: message: "CompleteMultipartUploadResult" XML is not parsable. Message: XML or text declaration not at start of entity: line 32, column 0`. The solution is to strip white-space characters from the begining of the response.
1 parent bed8719 commit 84e57b6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

minio/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def fromstring(cls, root_name, data):
6969
:return: Returns an S3Element.
7070
"""
7171
try:
72-
return cls(root_name, cElementTree.fromstring(data))
72+
return cls(root_name, cElementTree.fromstring(data.strip()))
7373
except _ETREE_EXCEPTIONS as error:
7474
raise InvalidXMLError(
7575
'"{}" XML is not parsable. Message: {}'.format(

0 commit comments

Comments
 (0)