Skip to content

Commit

Permalink
Remove white-space characters before parsing XML (#792)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
miso-belica authored and harshavardhana committed Sep 2, 2019
1 parent bed8719 commit 84e57b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion minio/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def fromstring(cls, root_name, data):
:return: Returns an S3Element.
"""
try:
return cls(root_name, cElementTree.fromstring(data))
return cls(root_name, cElementTree.fromstring(data.strip()))
except _ETREE_EXCEPTIONS as error:
raise InvalidXMLError(
'"{}" XML is not parsable. Message: {}'.format(
Expand Down

0 comments on commit 84e57b6

Please sign in to comment.