I've inherited a pretty large / complex (internal) web portal (run under python 2.6.6), which has some mapping capabilities, using Mapnik 2.2.0. The web service has recently started throwing 500 errors when it tries to create some of the maps that are displayed, with the sole error:
$ Premature end of script headers: app.wsgi
The maps are generated from geojson that is passed as a string (having been created from a python dictionary); I've tracked it down to 1 line of code in a
map.py, which adds a layer to a map:
data = mapnik.Ogr(file=json, layer='OGRGeoJSON')
when I comment out that line of code (and the associated
m.layers[-1].data = data) then the image is displayed on the portal, but obviously without this layer. The json is valid (I have checked it on http://geojsonlint.com).
Using a separate json file
I wanted to see whether calling the JSON from an external source replicated the problem. I therefore saved the json string as a separate file (
test.json), in the same directory as
map.py, and modified the
Ogr call to
data = mapnik.Ogr(file='test.json', layer='OGRGeoJSON')
I still get a 500 error, but with a slightly more verbose error message:
datasource = mapnik.Ogr(file='testgeo.json', layer='OGRGeoJSON') File /usr/lib64/python2.6/site-packages/mapnik/__init__.py, line 536, in Ogr return CreateDatasource(keywords) RuntimeError: OGR Plugin: Failed to read GeoJSON data
Checking the geojson
$ ogrinfo testgeo.json ERROR 4: GeoJSON Driver doesn't support update. Had to open data source read-only. INFO: Open of `testgeo.json' using driver `GeoJSON' successful. 1: OGRGeoJSON (3D Polygon)
So the json seems valid
Using the python command line
I have also tried running python interactively in the same directory as
$ python Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import mapnik >>> mapnik.Ogr(file="testgeo.json", layer="OGRGeoJSON") <mapnik.Datasource object at 0x7f6243c27398>
$ gdal-config --version 1.9.2 $ ogr2ogr --version GDAL 1.9.2, released 2012/10/08
This returns with no errors (so I assume that this means the geojson is valid, confirming my earlier test of running the geojson through http://geojsonlint.com):
$ ogr2ogr testgeo.shp testgeo.json
$ lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.7 (Final) Release: 6.7 Codename: Final
These 3 debugging efforts show that the json is valid and that the call works, except when it's run through the webstack. I've checked the permissions and ownership of all relevant files and directories, and they all seem to be as I'd expect.
What else could be causing the issue?!
Update (2 weeks after asking the original question)
I have come into work today and thought I'd have another crack at looking to see if I could tease some error messages out (new week, fresh start). But, utterly bizarrely, the code does not seem to be failing (for now, at least). I have changed nothing, and as far as I can gather, there have been no hardware changes to the servers.
This now becomes an investigation of what did cause it, and whether there's anything I can do to prevent it happening again...