Sansung YH-920 + Linux + yh-925-db-0.1.py = AttributeError: 'module' object has no attribute 'decode'

John Machin sjmachin at lexicon.net
Sat Jul 22 19:09:54 EDT 2006


rsd wrote:
> Hi,
>
> I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux.
> To do that I need to run
>    http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py
> script, the idea behind the script is described at
>    http://www.paul.sladen.org/toys/samsung-yh-925/
>
> I'm getting errors and hoping someone could give me some hints, for I
> have no python background.
>
> This is what I've done:
> 1. mounted YH-920 as /mnt/usb and transfered my MP3s to
> /mnt/usb/System/music/mp3 folder. That was easy.
>
> 2. Now, I need to run "yh-925-db-0.1.py" to update the database.
>
[snip]

>
>
> test:/mnt/usb/System# ./yh-925-db-0.1.py
> Traceback (most recent call last):
> File "./yh-925-db-0.1.py", line 195, in ?
> de.add_from_dict(e.unpack3(f))
> File "./yh-925-db-0.1.py", line 53, in unpack3
> u = utf_16_le.decode(fp.read(size))
> AttributeError: 'module' object has no attribute 'decode'
>
> Any ideas? Thanks

You don't say which version of Python you are running ... but my guess
is that it's 2.3 or earlier.

What the author is doing appears to be undocumented in Python 2.4 and
not supported in 2.3 & earlier.


Option (1): Upgrade your Python to 2.4 (visit www.python.org).
Option (2): Pass this problem description on to the author:

C:\junk>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.

|>> from encodings import utf_16_le
# The above is not documented.

# get some sample data in utf-16-le encoding:
|>> u = u'abcdef'
|>> u
u'abcdef'
|>> le16 = u.encode('utf-16-le')
|>> le16
'a\x00b\x00c\x00d\x00e\x00f\x00'

|>> utf_16_le.decode(le16)
(u'abcdef', 12)
# Doesn't work on Python 2.3 and earlier -- the decode() and encode()
functions are not exposed.
# Note: returns a tuple containing (unicode_object, length_in_bytes).
In the Python script for the music player,  the length is not used and
the unicode object has to be extracted by doing the_tuple[0]

# One documented way of decoding a string strg using encoding enc is
strg.decode(enc)
|>> le16.decode('utf-16-le')
u'abcdef'
# ... but this was introduced in 2.2. The builtin unicode(strg, enc)
function (also documented) does the same thing & works all the way back
to Python 2.1 at least (I didn't keep copies of 1.6 & 2.0) . I've heard
of Linux users stuck on 2.1 for whatever reason but not on earlier
versions.

C:\junk>c:\python21\python
Python 2.1.3 (#35, Apr  8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
|>> from encodings import utf_16_le
|>> u = u'abcdef'
|>> u
u'abcdef'
|>> le16 = u.encode('utf-16-le')
|>> le16
'a\x00b\x00c\x00d\x00e\x00f\x00'
|>> utf_16_le.decode(le16)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'encodings.utf_16_le' module has no attribute 'decode'
|>> unicode(le16, 'utf-16-le')
u'abcdef'
|>>

Option (3): hack the source code along the above lines ...
Option (4): hope somebody will hack it for you ....

HTH,
John




More information about the Python-list mailing list