I removed these calls to codecs because I got the error: ValueError: can't have text and binary mode at once