Friday, December 29, 2017

Possible bug: OutputWrapper: TypeError: write() argument must be str, not bytes

Hello all!
I'm new to the list and mostly new to Django.

I am adding django-encrypted-model-fields to my Django project and one of the steps to install it is to generate a key using a ./ command:
$ ./ generate_encryption_key

When executing it, an error is raised:
Traceback (most recent call last):
  File "./", line 22, in <module>
  File "/usr/local/lib/python3.6/site-packages/django/core/management/", line 371, in execute_from_command_line
  File "/usr/local/lib/python3.6/site-packages/django/core/management/", line 365, in execute
  File "/usr/local/lib/python3.6/site-packages/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/", line 335, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/encrypted_model_fields/management/commands/", line 15, in handle
    self.stdout.write(key, ending=b'\n')
  File "/usr/local/lib/python3.6/site-packages/django/core/management/", line 106, in write
TypeError: write() argument must be str, not bytes

I have found a workaround for this, decoding output before writing to stdout, on django/core/management/, line 106:

$ diff django/core/management/ django/core/management/
<         self._out.write(style_func(msg))
>         self._out.write(style_func(msg).decode(self._out.encoding))

Do I have to do a pull request to Django or try to debug django-encrypted-model-fields and talk to their developers?

Thanks in advance!
em and best regardsi

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment