Cherrypy / dev / urandom (or equivalent) not found - error

I start the cherrypy 3.2.0 server with Python 2.5.1, which every few days gives the following error from any command from the user interface until it is killed and restarted: -

[29/Mar/2012:06:37:57] HTTP Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 636, in respond
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 97, in run
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 57, in __call__
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 757, in init
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 162, in __init__
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 190, in _regenerate
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 204, in generate_id
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cpcompat.py", line 264, in random20
File "/usr/lib/python2.5/os.py", line 733, in urandom
NotImplementedError: /dev/urandom (or equivalent) not found

_cpcompat.pyhas the following code snippet, which says that random.randomthere is a reserve in case the cherry cannot read /dev/urandom, but does not seem to return to it.

try:
    os.urandom(20)
    import binascii
    def random20():
        return binascii.hexlify(os.urandom(20)).decode('ascii')

except (AttributeError, NotImplementedError):
    import random
    # os.urandom not available until Python 2.4. Fall back to random.random.
    def random20(): 
        return sha('%s' % random.random()).hexdigest()

code>

The following is a snippet of code from os.pythat is relevant in context: -

if not _exists("urandom"):

    def urandom(n):
        """urandom(n) -> str

        Return a string of n random bytes suitable for cryptographic use.

        """
        try:
            _urandomfd = open("/dev/urandom", O_RDONLY)
        except (OSError, IOError):
            raise NotImplementedError("/dev/urandom (or equivalent) not found")
        bytes = ""
        while len(bytes) < n:
            bytes += read(_urandomfd, n - len(bytes))
        close(_urandomfd)
        return bytes

code> At the same time, when cherrypy cannot read /dev/urandom, the following code fragment works fine: -

python -c "import os;fd = open('/dev/urandom', 'r');print fd.read(5);fd.close()"

I have two questions: -

  • Why does the worm throw an unrealized error when I can read random bits from / dev / urandom
  • _cpcompact.py , os.py NotImplementedError.
+5
3

, , , NotImplementedError , , " " , . , .

, ,

,

Exception in thread Plotter:
Traceback (most recent call last):
  File "threading.pyc", line 532, in __bootstrap_inner
  File "plotters/edge.pyc", line 459, in run
  AttributeError: 'error' object has no attribute 'error'

OSError: [Errno 24] Too many open files
  File "multiprocessing/connection.pyc", line 150, in Client
  File "multiprocessing/connection.pyc", line 370, in deliver_challenge
    None
  File "os.pyc", line 756, in urandom
NotImplementedError: /dev/urandom (or equivalent) not found

My AttributeError, , ... /urandom imlp error

+4

, , , os.py ( , , import os, )

if not _exists("urandom"):
    def urandom(n):
        """urandom(n) -> str

        Return a string of n random bytes suitable for cryptographic use.

        """
        try:
            _urandomfd = open("/dev/urandom", O_RDONLY)
        # debug changes
        except (OSError, IOError) as Err:
            import syslog
            syslog.syslog(repr(Err))
        # /debug
            raise NotImplementedError("/dev/urandom (or equivalent) not found")
        bytes = ""
        while len(bytes) < n:
            bytes += read(_urandomfd, n - len(bytes))
        close(_urandomfd)
        return bytes

, , . ( , , syslog ..)

+1

If your system does not already have / dev / random and / dev / urandom, they can be created using the following commands:

mknod -m 644 / dev / random c 1 8

mknod -m 644 / dev / urandom c 1 9

chown root: root / dev / random / dev / urandom

0
source

All Articles