Routes and cherrypy

41 views
Skip to first unread message

Jeremy

unread,
Jul 11, 2008, 7:02:09 AM7/11/08
to cherrypy-users
Hi

I'm currently trying to change a bit what my url look like.

I currently have url like :
http://www.naphtaline.net/projects/some_name/bug/10
http://www.naphtaline.net/logMeIn/some_name/bug/10

Which works very fine. But for various reasons,I'd like to use url
like that :
http://projects.naphtaline.net/some_name/bug/10
http://projects.naphtaline.net/some_name/logMeIn/bug/10

which would allow the user to find all the pages related to his own
project at http://projects.naphtaline.net/some_name

I was using that code :
d.connect('logMeIn', '/logMeIn/:project/:category/:idEntry',
controller=root, action='logMeIn', category='bug', idEntry=0)
d.connect('projects', '/projects/:project/:category/:idEntry',
controller=root, action='projects', category='bug', idEntry=0)

And I changed it for that :
d.connect('logMeIn', '/:project/logMeIn/:category/:idEntry',
controller=root, action='logMeIn', category='bug', idEntry=0)
d.connect('projects', '/:project/:category/:idEntry', controller=root,
action='projects', category='bug', idEntry=0)

The issue is that I could potentially have a project called "logMeIn"
and therefore there may be a conflict.
I went to #pylons to talk about Routes and they told me there should
be no issue since routes stops at the first url matched. I just have
to be careful about the order of the entries.

However, when I try the new code, I get this error from cherrypy, and
it does not want to start.

Traceback (most recent call last):
File "naphtaline.py", line 1699, in ?
cherrypy.engine.start()
File "/var/lib/python-support/python2.4/cherrypy/_cpengine.py", line
77, in start
cherrypy.checker()
File "/var/lib/python-support/python2.4/cherrypy/_cpchecker.py",
line 24, in __call__
method()
File "/var/lib/python-support/python2.4/cherrypy/_cpchecker.py",
line 55, in check_static_paths
request.get_resource(section + "/dummy.html")
File "/var/lib/python-support/python2.4/cherrypy/_cprequest.py",
line 628, in get_resource
dispatch(path)
File "/var/lib/python-support/python2.4/cherrypy/_cpdispatch.py",
line 253, in __call__
func = self.find_handler(path_info)
File "/var/lib/python-support/python2.4/cherrypy/_cpdispatch.py",
line 274, in find_handler
result = self.mapper.match(path_info)
File "/usr/lib/python2.4/site-packages/Routes-1.8-py2.4.egg/routes/
base.py", line 826, in match
result = self._match(url)
File "/usr/lib/python2.4/site-packages/Routes-1.8-py2.4.egg/routes/
base.py", line 805, in _match
self.sub_domains_ignore, self.domain_match)
File "/usr/lib/python2.4/site-packages/Routes-1.8-py2.4.egg/routes/
base.py", line 409, in match
if environ.get('HTTP_HOST') and sub_domains:
File "/var/lib/python-support/python2.4/cherrypy/_cpdispatch.py",
line 224, in __getattr__
return getattr(cherrypy.request.wsgi_environ, key)
File "/var/lib/python-support/python2.4/cherrypy/__init__.py", line
235, in __getattr__
return getattr(child, name)
AttributeError: 'Request' object has no attribute 'wsgi_environ'

Any idea ?

Robert Brewer

unread,
Jul 11, 2008, 12:29:11 PM7/11/08
to cherryp...@googlegroups.com

The error is arising because cherrypy.checker is trying to do static
analysis of your code, but the Routes implementation denies that since
it depends on a runtime-only structure, a WSGI environ. You can either
add a fake wsgi_environ attribute to the cherrypy.request object in the
main thread:

cherrypy.request.wsgi_environ = {fake data}

...or turn off that check:

cherrypy.checker.check_static_paths = None


Robert Brewer
fuma...@aminus.org

Jeremy

unread,
Jul 13, 2008, 9:53:01 AM7/13/08
to cherrypy-users
I must say, I have no idea of what a WSGI is.
Other than solving my issue, what are the consequences of turning of
the check ? (Giving fake data does not seem like a good idea for me)
> fuman...@aminus.org

Robert Brewer

unread,
Jul 14, 2008, 4:31:04 PM7/14/08
to cherryp...@googlegroups.com
> Other than solving my issue, what are the consequences of turning off

> the check ? (Giving fake data does not seem like a good idea for me)

None; the check is just something CherryPy does to help identify places in your code that _might_ not have been written correctly. Any of its warnings are safe to ignore if you think you know what you're doing.


Robert Brewer
fuma...@aminus.org

Jeremy

unread,
Jul 15, 2008, 4:12:28 AM7/15/08
to cherrypy-users
I don't get any warning. And it runs smoothly.

thanks a lot !
> fuman...@aminus.org
Reply all
Reply to author
Forward
0 new messages