Prevent UnicodeEncodeError when reading headers