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

unsupported locale setting error in 2.1.0 #377

Closed
thornycrackers opened this issue Nov 29, 2019 · 4 comments
Closed

unsupported locale setting error in 2.1.0 #377

thornycrackers opened this issue Nov 29, 2019 · 4 comments

Comments

@thornycrackers
Copy link

Description:

I'm trying to import pudb into my code base with from pudb import set_trace; set_trace() and I get this error.

unsupported locale setting error

/opt/venv/lib/python3.6/site-packages/urwid/util.py in detect_encoding
line 58:         locale.setlocale(locale.LC_ALL, initial)
initial | ('en_US', 'UTF-8')
locale | <module 'locale' from '/usr/local/lib/python3.6/locale.py'>


/usr/local/lib/python3.6/locale.py in setlocale
line 598:     return _setlocale(category, locale)
category | 6
locale | 'en_US.UTF-8'

If I downgrade to 2.0.1 everything is fine. This is running inside the python:3.6-slim-stretch image.

Affected versions (if applicable)

2.1.0

@tonycpsu
Copy link
Collaborator

Likely related to #259 , #279 .

@hoopes
Copy link

hoopes commented Dec 12, 2019

I opened a stack overflow for this (before i saw this ticket...):

https://stackoverflow.com/questions/59295250/python-default-locale-unsupported-locale-setting/59305150#59305150

The locale error from the SO issue was being thrown from urwid when using pudb.

@pieqq
Copy link

pieqq commented Feb 12, 2020

Hello!

I'm using urwid for a TUI program I'm writing, and since urwid was updated to v2.1.0 I got the same issue when trying to run my program on Ubuntu Core 16.

Here is the output of locale -a and locale in UC16:

$ locale -a
C
C.UTF-8
POSIX

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

Because of this, when urwid tries to execute the code that was added for 2.1.0 in util.py, it fails. This issue can be replicated manually:

  1. Setup a device with Ubuntu Core 16 on it. You can also create a Linux container running UC16 or something similar.
  2. Log into your UC16 device/container, then:
$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('en_US', 'UTF-8')
>>> initial = locale.getlocale()
>>> locale.setlocale(locale.LC_ALL, initial)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/snap/qabro/102/usr/lib/python3.6/locale.py", line 598, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

jspricke added a commit to jspricke/urwid that referenced this issue Jun 26, 2020
Resetting the locale was introduced in 5dcf236, before that an invalid
locale was ignored. Restore the old behavior insofar that only valid
locales are restored.
This fixes the unit tests of scottkosty/vit with unset LANG.
@GuillaumeSeren
Copy link

GuillaumeSeren commented Aug 8, 2020

Hello,
I run into this issue while testing a package for gentoo on a chroot environment.

The issue append on the chroot env,
and append with urwid-2.1.0 and urwid-2.1.1

During the test of alot package

ERROR: tests.widgets.test_globals (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.widgets.test_globals
Traceback (most recent call last):
  File "/usr/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/var/tmp/portage/mail-client/alot-0.9.1/work/alot-0.9.1/tests/widgets/test_globals.py", line 22, in <module>
    from alot.widgets import globals as globals_
  File "/var/tmp/portage/mail-client/alot-0.9.1/work/alot-0.9.1/alot/widgets/globals.py", line 10, in <module>
    import urwid
  File "/usr/lib/python3.7/site-packages/urwid/__init__.py", line 26, in <module>
    from urwid.widget import (FLOW, BOX, FIXED, LEFT, RIGHT, CENTER, TOP, MIDDLE,
  File "/usr/lib/python3.7/site-packages/urwid/widget.py", line 27, in <module>
    from urwid.util import (MetaSuper, decompose_tagmarkup, calc_width,
  File "/usr/lib/python3.7/site-packages/urwid/util.py", line 61, in <module>
    detected_encoding = detect_encoding()
  File "/usr/lib/python3.7/site-packages/urwid/util.py", line 58, in detect_encoding
    locale.setlocale(locale.LC_ALL, initial)
  File "/usr/lib/python3.7/locale.py", line 608, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

The issue is fixed by that patch fd010f8
by @jspricke

--- a/urwid/util.py
+++ b/urwid/util.py
@@ -55,7 +55,10 @@ def detect_encoding():
         else:
             raise
     finally:
-        locale.setlocale(locale.LC_ALL, initial)
+        try:
+            locale.setlocale(locale.LC_ALL, initial)
+        except locale.Error:
+            pass

 if 'detected_encoding' not in locals():
     detected_encoding = detect_encoding()

I would like to see this fixed, let me know if I can test / help.

@ulidtko ulidtko closed this as completed in fd010f8 Aug 9, 2020
ulidtko added a commit that referenced this issue Aug 9, 2020
Ignore resetting to invalid locale (Closes: #377)
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

5 participants