Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError: codec can't encode characters #37

Closed
jnm opened this issue Jun 13, 2019 · 8 comments
Closed

UnicodeEncodeError: codec can't encode characters #37

jnm opened this issue Jun 13, 2019 · 8 comments

Comments

@jnm
Copy link
Member

jnm commented Jun 13, 2019

Not sure we should change any code here, but for some reason, I needed to export LANG=en_US.UTF-8 on a particular Ubuntu 18.04.2 LTS server to avoid this traceback:

Traceback (most recent call last):
  File "run.py", line 66, in <module>
    run()
  File "run.py", line 26, in run
    current_config = config.build()
  File "/tmp/kobo-install/helpers/config.py", line 206, in build
    self.__welcome()
  File "/tmp/kobo-install/helpers/config.py", line 1222, in __welcome
    CLI.colored_print("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557", CLI.COLOR_WARNING)
  File "/tmp/kobo-install/helpers/cli.py", line 46, in colored_print
    print(cls.colorize(message, color))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 5-69: ordinal not in range(256)

This was with Python 3.6.7 (traceback above) and Python 2.7.15+ (same error but showed the box-drawing characters instead of the \u escape codes). If nothing else, we can could close this issue and let it serve as a reference for anyone searching for this error.

@sagarrana
Copy link

anything??

@luisbauti92
Copy link

luisbauti92 commented Oct 3, 2019

any idea?:

localectl status

System Locale: LANG=en_US.UTF-8
VC Keymap: latam
X11 Layout: latam

Traceback (most recent call last):
  File "run.py", line 55, in <module>
    run(force_setup=True)
  File "run.py", line 26, in run
    current_config = config.build()
  File "/home/development/kobo-install/helpers/config.py", line 206, in build
    self.__welcome()
  File "/home/development/kobo-install/helpers/config.py", line 1224, in __welcome
    CLI.colored_print("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557", CLI.COLOR_WARNING)
  File "/home/development/kobo-install/helpers/cli.py", line 46, in colored_print
    print(cls.colorize(message, color))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-69: ordinal not in range(128)

@luisbauti92
Copy link

this worked for me:

Centos 7
python 2.7

PYTHONIOENCODING=utf8 python run.py

@noliveleger noliveleger pinned this issue Nov 27, 2019
@noliveleger noliveleger changed the title UnicodeEncodeError in CLI.colored_print UnicodeEncodeError : codec can't encode characters Nov 27, 2019
@noliveleger noliveleger changed the title UnicodeEncodeError : codec can't encode characters UnicodeEncodeError: codec can't encode characters Nov 27, 2019
@pixelead0
Copy link

Install error afetr commit e450d53:
python run.py -s

root_:/home/kubrick/www/kobo-install/templates/kobo-deployments/enketo_express,
destination_directory_:/home/kubrick/www/kobo-deployments/enketo_express,
filenames_:[u'config.json.tpl'],
--------------------
t:<string.Template object at 0x7f9fd5ba7590>,
template_variables:{u'PRIVATE_DOMAIN_NAME': u'kobo.private', u'GOOGLE_API_KEY': u'', u'SMTP_PASSWORD': u'', u'SMTP_USE_TLS': True, u'REDIS_CACHE_PORT': u'6380', u'POSTGRES_PASSWORD': u'Y~GbI+sS!pyOEG+x', u'KOBOCAT_SUBDOMAIN': u'kc', u'SMTP_HOST': None, u'MASTER_BACKEND_IP': u'192.168.31.217', u'MONGO_BACKUP_SCHEDULE': u'0 1 * * 0', u'USE_KPI_DEV_MODE': u'#', u'AWS_BACKUP_MONTHLY_RETENTION': u'12', u'SOFT_LIMIT': 134217728, u'KPI_PATH': u'', u'KPI_RAVEN_DSN': u'', u'SMTP_USER': u'', u'KOBO_SUPERUSER_USERNAME': u'super_admin', u'NGINX_EXPOSED_PORT': u'80', u'USE_BACKUP': u'#', u'AWS_REDIS_BACKUP_MINIMUM_SIZE': u'5', u'AWS_MONGO_BACKUP_MINIMUM_SIZE': u'50', u'KOBOFORM_SUBDOMAIN': u'kf', u'WSGI_SERVER': u'uWSGI', u'SMTP_PORT': u'25', u'USE_AWS': u'#', u'LETSENCRYPT_EMAIL': None, u'USE_DNS': u'', u'KPI_RAVEN_JS_DSN': u'', u'MAX_REQUESTS': u'512', u'POSTGRES_BACKUP_SCHEDULE': u'0 2 * * 0', u'ENKETO_ENCRYPTION_KEY': u'060bc0642c6d97041b8532f0f1a9d6356f1715241e112ab89522e47a31064420e8eb5c8a65752d16d8d26342b91bc881d5c04b815ee5ed719f0f058e', u'KPI_DEV_BUILD_ID': u'', u'PUBLIC_DOMAIN_NAME': u'kobo.local', u'USE_KC_DEV_MODE': u'#', u'INTERNAL_DOMAIN_NAME': u'kobo.internal', u'KOBO_SUPERUSER_PASSWORD': u'VgF9vbX4KPF+zu', u'AWS_BACKUP_BUCKET_DELETION_RULE_ENABLED': u'False', u'POSTGRES_APP_PROFILE': u'Mixed', u'MONGO_PORT': u'27017', u'USE_X_FORWARDED_HOST': u'#', u'KC_PATH': u'', u'PROTOCOL': u'http', u'ENKETO_SUBDOMAIN': u'ee', u'NGINX_PUBLIC_PORT': u'80', u'OVERRIDE_POSTGRES_SETTINGS': u'#', u'AWS_BACKUP_WEEKLY_RETENTION': u'4', u'AWS_BACKUP_BUCKET_NAME': u'', u'POSTGRES_RAM': u'2', u'POSTGRES_DB': u'kobotoolbox', u'REDIS_MAIN_PORT': u'6379', u'WORKERS_START': u'1', u'POSTGRES_REPLICATION_PASSWORD': u'u739sxpt+fGGaxJ', u'USE_AWS_BACKUP': u'#', u'AWS_BUCKET_NAME': u'', u'POSTGRES_SETTINGS': u'', u'AWS_POSTGRES_BACKUP_MINIMUM_SIZE': u'50', u'DEBUG': False, u'WORKERS_MAX': u'2', u'AWS_ACCESS_KEY_ID': u'', u'USE_HTTPS': u'#', u'USE_MEDIA_BACKUP': u'#', u'ENKETO_API_TOKEN': u'9d7b980debf40401a190f0e610f659aa52b3563a58465070480550c3fa8bb699403da84bbfcaa043bc2b65042e33c14b5ffcb711e43b0f5f46545455', u'POSTGRES_USER': u'kobo', u'USE_PUBLIC_DNS': u'#', u'KOBOCAT_MEDIA_BACKUP_SCHEDULE': None, u'GOOGLE_UA': u'', u'LOCAL_INTERFACE_IP': u'192.168.31.217', u'AWS_BACKUP_YEARLY_RETENTION': u'2', u'POSTGRES_PORT': u'5432', u'KC_DEV_BUILD_ID': u'', u'DJANGO_SECRET_KEY': u'9860f89729b9304bcf26507ed946f5eca0eb0fa05e0b01fb', u'AWS_BACKUP_DAILY_RETENTION': u'30', u'AWS_BACKUP_UPLOAD_CHUNK_SIZE': u'15', u'POSTGRES_BACKUP_FROM_SLAVE': u'#', u'DEFAULT_FROM_EMAIL': u'[email protected]', u'AWS_SECRET_ACCESS_KEY': u'', u'REDIS_BACKUP_SCHEDULE': u'0 3 * * 0', u'USE_PRIVATE_DNS': u'', u'KOBOCAT_RAVEN_DSN': u''},
++++++++++++++++++++
Traceback (most recent call last):
  File "run.py", line 55, in <module>
    run(force_setup=True)
  File "run.py", line 28, in run
    Template.render(config)
  File "/home/kubrick/www/kobo-install/helpers/template.py", line 159, in render
    write_templates(root, destination_directory, filenames)
  File "/home/kubrick/www/kobo-install/helpers/template.py", line 148, in write_templates
    f.write(t.substitute(template_variables))
  File "/usr/lib/python2.7/string.py", line 176, in substitute
    return self.pattern.sub(convert, self.template)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 689: ordinal not in range(128)


@AlexandreBonneau
Copy link

For info the using the latest version of kobo-install today (just git pull(ed)), and an updated Ubuntu 20.04 VPS, I had this error.
To fix it I had to use @luisbauti92 solution:

PYTHONIOENCODING=utf8 python3 run.py --update

@noliveleger
Copy link
Contributor

Hello @AlexandreBonneau,
Which language are you using with your system? I guess French? What does the command locale say?

@AlexandreBonneau
Copy link

You guessed right:

locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=fr_FR.UTF-8

@noliveleger
Copy link
Contributor

Merci beaucoup ;-)
We'll try with another language than English as default language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants