473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UnicodeDecodeError when importing random? (running with -U)

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.
>>import random
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)

Apr 13 '07 #1
1 1872
Ben wrote:
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.
>>>import random
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

Apr 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robin Siebler | last post by:
I have no idea what is causing this error, or how to fix it. The full error is: Traceback (most recent call last): File "D:\ScriptRuntime\PS\Automation\Handlers\SCMTestToolResourceToolsBAT.py",...
5
by: dixie | last post by:
If I sent a user an empty database container - dB with no tables and I needed them to import their tables into it and one of their tables was a hidden table with the prefix Usys, is there any way...
2
by: dbri.tcc | last post by:
Hello I am getting somewhat random UnicodeDecodeError messages in my program. It is random in that I will be going through a pysqlite database of records, manipulate the results, and it will...
4
by: Robin Haswell | last post by:
Okay I'm getting really frustrated with Python's Unicode handling, I'm trying everything I can think of an I can't escape Unicode(En|De)codeError no matter what I try. Could someone explain to...
4
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
39
by: Alan Isaac | last post by:
This may seem very strange, but it is true. If I delete a .pyc file, my program executes with a different state! In a single directory I have module1 and module2. module1 imports random and...
3
by: Jorgen Bodde | last post by:
Hi All, I am relatively new to python unicode pains and I would like to have some advice. I have this snippet of code: def playFile(cmd, args): argstr = list() for arg in...
0
by: Edwin.Madari | last post by:
if you can print out values of 'filemask', and 'thefile' variables, when it crashes, I can help. thx. Edwin -----Original Message----- From:...
1
by: Wayne | last post by:
I've found a painful bug when running an Access 2003 database under Access 2007. It manifests in both XP and Vista. Some combo boxes on some forms become transparent when they lose focus. It...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.