UnicodeDecodeError when importing random? (running with -U)

B

Ben

Is the following a known bug?

[temp]$ python -U
Python 2.4.4 (#1, Oct 23 2006, 13:58:18)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib64/python2.4/random.py", line 834, in ?
_inst = Random()
File "/usr/lib64/python2.4/random.py", line 94, in __init__
self.seed(x)
File "/usr/lib64/python2.4/random.py", line 108, in seed
a = long(_hexlify(_urandom(16)), 16)
File "/usr/lib64/python2.4/os.py", line 723, in urandom
bytes += read(_urandomfd, n - len(bytes))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x97 in position
0: ordinal not in range(128)
 
R

Robert Kern

Ben said:
Is the following a known bug?

[temp]$ python -U
Python 2.4.4 (#1, Oct 23 2006, 13:58:18)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib64/python2.4/random.py", line 834, in ?
_inst = Random()
File "/usr/lib64/python2.4/random.py", line 94, in __init__
self.seed(x)
File "/usr/lib64/python2.4/random.py", line 108, in seed
a = long(_hexlify(_urandom(16)), 16)
File "/usr/lib64/python2.4/os.py", line 723, in urandom
bytes += read(_urandomfd, n - len(bytes))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x97 in position
0: ordinal not in range(128)

It's unsurprising, certainly. It's not a bug in 2.4, though. -U is for
experimentation only, not for actual use. Python will change to only using
Unicode strings in 3.0, but not before then. Python 3.0 will add a bytes type to
replace non-text strings like those read from /dev/urandom in that piece of
code. os.urandom() and the random module will have to be modified to use it
instead of a string. Looking at the Python 3.0 branch, I see that this hasn't
quite happened, yet.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top