Skip to content

Commit dd58f3d

Browse files
committed
Open metadata in binary mode for Python 3 compatibility.
Python 3 handles character data read from a file differently than Python 2 does. Python 3 opens files in text mode by default, causing file reads to return string data decoded from file using encoding specified as argument of open() builtin function. If encoding is not specified, open() uses some default encoding that can even be ASCII. Hence, using open() in text mode without specifying encoding is dangerous in Python 3 and can lead to unexpected results. However, it's safe to open metadata in binary mode, it gets encoded to UTF-8 later anyway. Signed-off-by: Oleg Girko <[email protected]>
1 parent 248c629 commit dd58f3d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/saml2/mdstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def __init__(self, onts, attrc, filename=None, cert=None, **kwargs):
589589
self.cert = cert
590590

591591
def get_metadata_content(self):
592-
return open(self.filename).read()
592+
return open(self.filename, 'rb').read()
593593

594594
def load(self):
595595
_txt = self.get_metadata_content()

0 commit comments

Comments
 (0)