Sto eseguendo un server cherrypy 3.2.0 con Python 2.5.1, che dà il seguente errore ogni pochi giorni su qualsiasi istruzione dall'interfaccia utente fino a quando non viene ucciso e riavviato: -cherrypy/dev/urandom (o equivalente) non trovato - errore
[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.py
ha seguente pezzo di codice che suggerisce che v'è un ripiego su random.random
nel caso in cui CherryPy non è in grado di leggere /dev/urandom
, ma non sembra essere ricadere su di essa.
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()
seguito è il frammento di codice da os.py
, rilevante nel contesto: -
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
Allo stesso tempo, quando cherrypy non è in grado di leggere
/dev/urandom
, il seguente frammento di codice sta lavorando bene: -
python -c "import os;fd = open('/dev/urandom', 'r');print fd.read(5);fd.close()"
ho due domande: -
- Perché cherrypy gettando errore non implementato quando sono in grado di leggere bit casuali da/dev/urandom
- Perché
_cpcompact.py
non esecuzione del tranne quando parteos.py
sta sollevandoNotImplementedError
.
fa ' python -c "import os; print os.urandom (5) "' lavoro? – tMC
purtroppo, lo fa, mentre cherrypy dice/dev/urandom non implementato! – haltTm
Forse le autorizzazioni sono rovinate da qualche parte? – sdolan