Repository: ckan/ckan

Issue:
500 Error Upon Production Deployment
Hi everyone,

I was able to get CKAN working just fine locally, but trying to deploy per the instructions (http://docs.ckan.org/en/latest/deployment.html) gives me a 500 error. I checked permissions and everything is correct. Here's the log:

```
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157] mod_wsgi (pid=17063): Target WSGI script '/etc/ckan/default/apache.wsgi' cannot be loaded as Python module.
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157] mod_wsgi (pid=17063): Exception occurred processing WSGI script '/etc/ckan/default/apache.wsgi'.
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157] Traceback (most recent call last):
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/etc/ckan/default/apache.wsgi", line 9, in <module>
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     application = loadapp('config:%s' % config_filepath)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     return loadobj(APP, uri, name=name, **kw)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     return context.create()
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 710, in create
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     return self.object_type.invoke(self)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     return fix_call(context.object, context.global_conf, **context.local_conf)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/util.py", line 56, in fix_call
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     val = callable(*args, **kw)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckan/config/middleware.py", line 54, in make_app
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     load_environment(conf, app_conf)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckan/config/environment.py", line 177, in load_environment
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     config['routes.map'] = routing.make_map()
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckan/config/routing.py", line 100, in make_map
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     map = plugin.before_map(map)
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckanext/datastore/plugin.py", line 248, in before_map
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157]     print "Load mapping"
[Mon Jul 15 20:31:51 2013] [error] [client 198.211.103.157] IOError: sys.stdout access restricted by mod_wsgi
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157] mod_wsgi (pid=17064): Target WSGI script '/etc/ckan/default/apache.wsgi' cannot be loaded as Python module.
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157] mod_wsgi (pid=17064): Exception occurred processing WSGI script '/etc/ckan/default/apache.wsgi'.
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157] Traceback (most recent call last):
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/etc/ckan/default/apache.wsgi", line 9, in <module>
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     application = loadapp('config:%s' % config_filepath)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     return loadobj(APP, uri, name=name, **kw)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     return context.create()
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 710, in create
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     return self.object_type.invoke(self)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     return fix_call(context.object, context.global_conf, **context.local_conf)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/lib/python2.6/site-packages/paste/deploy/util.py", line 56, in fix_call
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     val = callable(*args, **kw)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckan/config/middleware.py", line 54, in make_app
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     load_environment(conf, app_conf)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckan/config/environment.py", line 177, in load_environment
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     config['routes.map'] = routing.make_map()
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckan/config/routing.py", line 100, in make_map
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     map = plugin.before_map(map)
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]   File "/usr/lib/ckan/default/src/ckan/ckanext/datastore/plugin.py", line 248, in before_map
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157]     print "Load mapping"
[Mon Jul 15 20:31:55 2013] [error] [client 198.211.103.157] IOError: sys.stdout access restricted by mod_wsgi
[Mon Jul 15 20:36:53 2013] [error] Exception KeyError: KeyError(140103623919424,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored
[Mon Jul 15 20:36:53 2013] [error] Exception KeyError: KeyError(140103623919424,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored
[Mon Jul 15 20:36:54 2013] [error] Exception AttributeError: "'NoneType' object has no attribute 'clearing'" in <bound method PluginEnvironment.__del__ of  Services for Environment '<default>'
[Mon Jul 15 20:36:54 2013] [error] > ignored
[Mon Jul 15 20:36:54 2013] [error] Exception AttributeError: "'NoneType' object has no attribute 'clearing'" in <bound method PluginEnvironment.__del__ of  Services for Environment '<default>'
[Mon Jul 15 20:36:54 2013] [error] > ignored
[Mon Jul 15 20:36:59 2013] [error] Load mapping
[Mon Jul 15 20:37:02 2013] [error] 2013-07-15 20:37:02,827 INFO  [ckan.lib.base]  / render time 2.856 seconds
```



Discussion:
Thanks for reporting this bug.  The print statement in `ckan/ckanext/datastore/plugin.py`, line 248 should not be there and apache does not like it.  You can delete it.

Thanks for reporting this bug.  The print statement in `ckan/ckanext/datastore/plugin.py`, line 248 should not be there and apache does not like it.  You can delete it.

So I was trying to be clever and branch this off the 2.1 release branch commit      a5e601b is all we care about

@domoritz can you cherry pick into master and get into 2.1 :)


Resolving patch:
diff --git a/ckanext/datastore/plugin.py b/ckanext/datastore/plugin.py
--- a/ckanext/datastore/plugin.py
+++ b/ckanext/datastore/plugin.py
@@ -245,7 +245,6 @@ def get_auth_functions(self):
                 'datastore_change_permissions': auth.datastore_change_permissions}
 
     def before_map(self, m):
-        print "Load mapping"
         m.connect('/datastore/dump/{resource_id}',
                   controller='ckanext.datastore.controller:DatastoreController',
                   action='dump')


Test patch: