I'm building my first web app with authentication in cherrypy: the auth piece works, but after the login I get the error 405 Method Not Allowed
Specified method is invalid for this resource
. Any idea on how to overcome it?
Thanks in advance!
from cherrypy.lib import auth_digest
import cherrypy
USERS = {'jon': 'secret'}
config = {
'global' : {
'server.socket_host' : '127.0.0.1',
'server.socket_port' : 8080,
'server.thread_pool' : 8,
'log.screen' : True
},
'/' : {
# HTTP verb dispatcher
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
# JSON response
'tools.json_out.on' : True,
# Digest Auth
'tools.auth_digest.on' : True,
'tools.auth_digest.realm' : 'walledgarden',
'tools.auth_digest.get_ha1' : auth_digest.get_ha1_dict_plain(USERS),
'tools.auth_digest.key' : 'generate_something_random',
}
}
class HelloWorld():
def index(self):
return "Hello World!"
index.exposed = True
#cherrypy.quickstart(HelloWorld(), config=None) #this works
cherrypy.quickstart(HelloWorld(), config=config) #this is broken
Thanks to cyraxjoe
pointers I figured it out:
from cherrypy.lib import auth_digest
import cherrypy
USERS = {'jon': 'secret'}
config = {'/': {'tools.auth_digest.on': True,
'tools.auth_digest.realm': 'walledgarden',
'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(USERS),
'tools.auth_digest.key': 'generate_something_random',
}}
class HelloWorld():
def index(self):
return "Hello World!"
index.exposed = True
#cherrypy.quickstart(HelloWorld(), config=None) #this works -- NO AUTHENTICATION
cherrypy.quickstart(HelloWorld(), config=config) #WORKS WITH AUTHENTICATION