<class 'UnicodeEncodeError'>: 'ascii' codec can't encode characters in position 18-25: ordinal not in range(128)

Bug #1058038 reported by Антон Дерлюк
50
This bug affects 10 people
Affects Status Importance Assigned to Milestone
Python
Invalid
Unknown
aptdaemon (Ubuntu)
Fix Released
Medium
Unassigned
python3.2 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/aptdaemon/worker.py", line 1181, in _simulate
    trans.unauthenticated, trans.high_trust_packages = self.__simulate(trans)
  File "/usr/lib/python3/dist-packages/aptdaemon/worker.py", line 1239, in __simulate
    deb = self.install_file(trans, simulate=True, **trans.kwargs)
  File "/usr/lib/python3/dist-packages/aptdaemon/worker.py", line 740, in install_file
    deb = self._check_deb_file(trans, path, force)
  File "/usr/lib/python3/dist-packages/aptdaemon/worker.py", line 1326, in _check_deb_file
    if not os.path.isfile(path):
  File "/usr/lib/python3.2/genericpath.py", line 29, in isfile
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 18-25: ordinal not in range(128)

ProblemType: Crash
DistroRelease: Ubuntu 12.10
Package: aptdaemon 0.45+bzr861-0ubuntu5
ProcVersionSignature: Ubuntu 3.5.0-15.23-generic 3.5.4
Uname: Linux 3.5.0-15-generic i686
Annotation: Installation of the package file failed
ApportVersion: 2.5.2-0ubuntu4
Architecture: i386
Date: Fri Sep 28 16:53:16 2012
ExecutablePath: /usr/sbin/aptd
InstallationMedia: Ubuntu 12.10 "Quantal Quetzal" - Beta i386 (20120926)
PackageArchitecture: all
SourcePackage: aptdaemon
Title: <class 'UnicodeEncodeError'>: 'ascii' codec can't encode characters in position 18-25: ordinal not in range(128)
TransactionDepends: [[], [], [], [], [], [], []]
TransactionErrorCode: error-unknown
TransactionKwargs: {'path': dbus.String('/home/silentlight/Загрузки/google-chrome-stable_current_i386.deb'), 'force': dbus.Boolean(False)}
TransactionLocale: ru_RU.UTF-8
TransactionOutput:

TransactionPackages: [[], [], [], [], [], []]
TransactionRole: role-install-file
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Антон Дерлюк (gespenst-vs) wrote :
tags: removed: need-duplicate-check
Changed in aptdaemon (Ubuntu):
importance: Undecided → Medium
Julian Taylor (jtaylor)
visibility: private → public
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in aptdaemon (Ubuntu):
status: New → Confirmed
Revision history for this message
Josef Andersson (northar) wrote :

Trying to install something from /home/myuser/Hämt/fs-uae_1.3.29-0_amd64.deb
gives this bug with lates quantal updates (x64)

When skipping folder /Hämt/ in the path it works.Uniode prob?

Revision history for this message
Nicolas Delvaux (malizor) wrote :

This is indeed a unicode problem.
The strange thing is that it works when killing and launching aptd from the command line.

According to http://docs.python.org/py3k/howto/unicode.html#unicode-filenames , this is because the LANG environment variable is not set when aptd is spawned by the sotware-center. In this case, the default encoding for pathes is ASCII.
I hacked arround and was able to confirm this (by writing os.environ in a file).

So here is the bug.
Though, I'm not sure about the best way to fix it.

Revision history for this message
walterclozet (walterclozet-u) wrote :

trying to install chrome amd64 for ubuntu, download from official site. crushes every time when double click to install.

Revision history for this message
Michael Vogt (mvo) wrote :

I can confirm this, when LANG/LANUAGE is unset and LC_CTYPE is set to posix/C the sys.getfilesystemencoding() call
will return "ascii".

Revision history for this message
Michael Vogt (mvo) wrote :

Looking at this a bit more it appears to be a bit of a can of worms. It appears that the dbus activation sytem
is launching the daemon with a almost empty env:
environ(
{'DBUS_STARTER_BUS_TYPE': 'system',
 'DBUS_STARTER_ADDRESS': 'unix:path=/var/run/dbus/system_bus_socket'})

which means that even the systemwide default language is not set.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Michael Vogt (mvo)
affects: python-defaults (Ubuntu) → python3.2 (Ubuntu)
Changed in python3.2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Michael Vogt (mvo) wrote :

AFAICT the default fsencoding is read only at python startup and can not be changed later. The dbus activation does run the aptd without a env (well, just a minimal one).

<cjwatson> Or else there needs to be a way to break the caching when we change Python's locale at run-time
<cjwatson> That might be a good idea anyway
<mvo> cjwatson: yeah, that would be the cleanest I think, ensuring this is reset on setlocale()
<pitti> yeah, a locale.setlocale() call ought to change the fs encoding, toovalid env

Allowing to change the encoding later is probably the best option.

Revision history for this message
Michael Vogt (mvo) wrote :

<pitti> just saying that if all else fails, hardcoding utf-8 shoudl avoid 99% of the problems with a really trivial/safe patch?

Revision history for this message
Sebastian Heinlein (glatzor) wrote : Re: [Bug 1058038] Re: <class 'UnicodeEncodeError'>: 'ascii' codec can't encode characters in position 18-25: ordinal not in range(128)

We should unset those variables in the test suite or even use dbus activation for the daemon testing. But makes cleaning up in the tests a little bit tricky. Someting to target for R.
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

Revision history for this message
Sebastian Heinlein (glatzor) wrote :

We could also set lang to C.UTF8 in aptdaemon only.

Michael Vogt <email address hidden> schrieb:

><pitti> just saying that if all else fails, hardcoding utf-8 shoudl
>avoid 99% of the problems with a really trivial/safe patch?
>
>--
>You received this bug notification because you are a member of
>Aptdaemon
>Developers, which is subscribed to aptdaemon in Ubuntu.
>https://bugs.launchpad.net/bugs/1058038
>
>Title:
> <class 'UnicodeEncodeError'>: 'ascii' codec can't encode characters in
> position 18-25: ordinal not in range(128)
>
>To manage notifications about this bug go to:
>https://bugs.launchpad.net/ubuntu/+source/aptdaemon/+bug/1058038/+subscriptions

--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

Revision history for this message
Michael Vogt (mvo) wrote :

@Sebastian:
we would have to use a shell wrapper or fork/exit as the env is read on interpreter statup.

Revision history for this message
Michael Vogt (mvo) wrote :
Michael Vogt (mvo)
Changed in dbus (Ubuntu):
status: New → Invalid
tags: added: patch
Changed in python:
status: Unknown → New
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python3.2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Michael Vogt (mvo) wrote :

The attached branch works around the problem by setting up a basic LANG env and doing a a os.execv()

no longer affects: dbus (Ubuntu)
Changed in python:
status: New → Invalid
Matthias Klose (doko)
Changed in python3.2 (Ubuntu):
status: Confirmed → Invalid
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package aptdaemon - 0.45+bzr861-0ubuntu9

---------------
aptdaemon (0.45+bzr861-0ubuntu9) quantal; urgency=low

  * Workaround that ensures that for sys.getfilesystemencoding()
    "utf8" is used when the daemon is dbus auto-activatied (LP: #1058038)
 -- Michael Vogt <email address hidden> Tue, 09 Oct 2012 14:27:36 +0200

Changed in aptdaemon (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.