Userland: Python3 bug!!

Created on 6 Dec 2018  路  10Comments  路  Source: CypherpunkArmory/UserLAnd

every time I try to run my program an error is returned, and my program works in other apps

Error:

Traceback (most recent call last):
File "/sdcard/pythonP/ex95.py", line 16, in
gols[f"partida{g}"] = int(input(f"quantidade de gols na
partida {g}\xaa: "))
UnicodeEncodeError: 'ascii' codec can't encode character '\x
aa' in position 31: ordinal not in range(128)

Most helpful comment

You need to provide everything necessary for the issue to be replicated.

All 10 comments

You need to provide everything necessary for the issue to be replicated.

can you provide the source code and the commands (packages we need to install, etc) to reproduce?

@m4rkito it seems like you're trying to output a string with non-ASCII characters in it. Have you tried prepending LANG=C.UTF-8 to your python command and seeing if that helps (Do LANG=C.UTF8 python3 your-script.py)? (At least the ubuntu image) seems to default to the C locale, which is ASCII-only.

yes my problem is with characters that I'm using and are not in the ASCII standard, I wanted to know how to solve it easily

@m4rkito I really need you to provide a reproducible case. That will allow us to properly understand you and recommend a fix. If you won't do that in the next 3 days. I will close this issue as there will be nothing I can do.

While I'm not @m4rkito, I believe that he's facing an issue that can be reproduced with the simple python script below:

#!/usr/bin/env python3
print("Hallo 脺mlaut!")

On Ubuntu this gives me the following error:

user@localhost:~$ python3 testcase.py
Traceback (most recent call last):
  File "testcase.py", line 2, in <module>
    print("Hallo \xdcmlaut!")
UnicodeEncodeError: 'ascii' codec can't encode character '\xdc' in position 6: ordinal not in range(128)

As I've already mentioned above, I believe this to be the result of an improperly configured locale in the Ubuntu rootfs (the build script makes references to the C locale, while C.UTF-8 would be required for Unicode support). When this locale is set (for example by doing export LANG=C.UTF-8) everything works properly.

This also breaks some other applications (for example, pipenv and mosh refuse to run in non-Unicode terminals).

I don't believe fixing it would be that hard (probably just changing a line in the build script of every affected distro). I'd submit the PR myself, but building the rootfs and loading it in the app for testing is unfortunately not documented. :(

Just looking at the error message, I was able to reproduce a similar enough scenario. After doing that. I can confirm that this solves the issue LANG=C.UTF-8 python3 your-script.py

Note: there was a - missing from the @caspt comment earlier

We added a wiki entry about how to add a distro or app. That also leads you to where you could build the existing ones. There are many places where we could fix something as simple as an environment variable though. I will add an internal issue to look into what our default LANG is. Thanks @casept for helping out.

@corbinlc This really solved my problem.
LANG=C.UTF-8 python3 your-script.py

$ export LANG = C.UTF-8
$ python3 your-script.py

This really solved my problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Enzycal picture Enzycal  路  7Comments

DevelopedLogic picture DevelopedLogic  路  7Comments

TechDossier picture TechDossier  路  3Comments

denomparkour picture denomparkour  路  4Comments

foodmaher picture foodmaher  路  8Comments