Reputation: 8481
My CherryPy app started throwing error 500 (see traceback below) when serving favicon. At first only a few computers had the problem, now all the computers get the error. I don't think I have changed anything on the Python app, perhaps something has changed on the computer configuration.
I am not able to debug the error because it does not reproduce on my development computer. On my computer it does not even reach the line where it crashes on the production server.
Here is the configuration (other parameters are added by other modules, this is the starting configuration that takes care of favicon):
config = {'global': {'server.socket_host': '0.0.0.0',
'server.socket_port': 80,
'log.error_file': 'log\\web.log',
'log.access_file': 'log\\access.log'},
'/favicon.ico': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.dirname(__file__) + '\\favicon.ico'}}
Here is the traceback:
[08/Jan/2016:13:55:14] HTTP
Request Headers:
ACCEPT-LANGUAGE: en-US,en;q=0.8
COOKIE: DocFinder_Id=2dde47f7-c679-4c12-a5c5-0a8a214c47d6
CONNECTION: keep-alive
REFERER: http://intelliweb.universecorp.com/doc/tmp/808184425.pdf
ACCEPT-ENCODING: gzip, deflate
USER-AGENT: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Remote-Addr: 192.1.1.120
ACCEPT: */*
HOST: intelliweb.universecorp.com
[08/Jan/2016:13:55:14] HTTP Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cherrypy\_cprequest.py", line 670, in respond
response.body = self.handler()
File "C:\Python34\lib\site-packages\cherrypy\lib\encoding.py", line 212, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "C:\Python34\lib\site-packages\cherrypy\_cpdispatch.py", line 61, in __call__
return self.callable(*self.args, **self.kwargs)
File "C:\Python34\lib\site-packages\cherrypy\_cptools.py", line 175, in handle_func
handled = self.callable(*args, **self._merged_args(kwargs))
TypeError: staticfile() got multiple values for argument 'filename'
192.1.1.120 - - [08/Jan/2016:13:55:14] "GET /favicon.ico HTTP/1.1" 500 1468 "http://intelliweb.universecorp.com/doc/tmp/808184425.pdf" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
Upvotes: 0
Views: 512
Reputation: 8481
misakm's answer was not correct, but helped me in the debugging: the problem was that __file__
was absolute on the development computer and relative on the production one. I found the reason here:
If you load a module in the current directory, and the current directory isn't in sys.path, you'll get an absolute path.
If you load a module in the current directory, and the current directory is in sys.path, you'll get a relative path.
The solution was to add abspath
like this:
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'favicon.ico')
The culprit was some maintenance performed a few weeks ago on the Windows environment which had changed the PATH.
Upvotes: 0
Reputation: 122
Try changing this line:
'tools.staticfile.filename': os.path.dirname(__file__) + '\\favicon.ico'
to
'tools.staticfile.filename': os.path.join(os.path.dirname(__file__), 'favicon.ico')
Another way is to serve your favicon from your html (in the header section):
<link href="yourpath/favicon.ico" rel="icon" type="image/x-icon" />
Upvotes: 1