Search code examples
pythonpyramidproductionwaitress

Server error when pyramid app hosted with production.ini


I have a pyramid project that works fine when hosted with development.ini, but as soon as I use production.ini I get this error in browser:

Internal Server Error
The server encountered an unexpected internal server error
(generated by waitress)

and this log in terminal:

Starting subprocess with file monitor
Starting server in PID 5912.
serving on http://0.0.0.0:6543
2014-05-26 16:54:23,139 ERROR [waitress][Dummy-2] Exception when serving /
Traceback (most recent call last):
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/waitress-0.8.9-py2.7.egg/waitress/channel.py", line 337, in service
    task.service()
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/waitress-0.8.9-py2.7.egg/waitress/task.py", line 173, in service
    self.execute()
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/waitress-0.8.9-py2.7.egg/waitress/task.py", line 392, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/router.py", line 242, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/router.py", line 217, in invoke_subrequest
    response = handle_request(request)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 82, in tm_tween
    reraise(*exc_info)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 63, in tm_tween
    response = handler(request)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/router.py", line 163, in handle_request
    response = view_callable(context, request)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/config/views.py", line 377, in rendered_view
    context)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/renderers.py", line 418, in render_view
    return self.render_to_response(response, system, request=request)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/renderers.py", line 441, in render_to_response
    result = self.render(value, system_values, request=request)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/renderers.py", line 421, in render
    renderer = self.renderer
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/decorator.py", line 37, in __get__
    val = self.wrapped(inst)
  File "/home/roman/Critical_ID/CCG_Map/local/lib/python2.7/site-packages/pyramid/renderers.py", line 404, in renderer
    'No such renderer factory %s' % str(self.type))
ValueError: No such renderer factory .mak

I copied over my sqlalchemy.url and mako.directories under the [app:main] section in the .ini files, and I can't see what is causing this error.

I start the server with: ../bin/pserve/production.ini --reload

What am I missing?


Solution

  • This is because the latest versions of Pyramid do not require/install Mako's templating engine by default. To fix this error, as documented HERE, you must do two things:

    1. Make sure the pyramid_mako package is installed. One way to do this is by adding "pyramid_mako" to the install_requires section of your package's setup.py file and afterwards rerunning setup.py develop:

      setup(
          #...
          install_requires=[
              'pyramid_mako',         # new dependency
              'pyramid',
              #...
          ],
      )
      
    2. Within the portion of your application which instantiates a Pyramid Configurator (often the main() function in your project's __init__.py file), tell Pyramid to include the pyramid_mako includeme:

      config = Configurator(.....)
      config.include('pyramid_mako')