[mapserver-users] Python MapScript via WSGI examples

Kralidis, Tom (EC) tom.kralidis at canada.ca
Fri Jul 15 11:05:50 PDT 2016


Thanks Julien and Stephan: I've updated my example in [1], however I get
the following traceback when issuing a WMS 1.1.1 GetMap request:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "mapscript-wsgi.py", line 40, in application
    start_response('200 OK', [('Content-type', content_type)])
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 180, in start_response
    assert type(val) is StringType,"Header values must be strings"
AssertionError: Header values must be string

Any idea?

..Tom

[1] https://gist.github.com/tomkralidis/9adbd4864c03647aa7eb4f96a3c33297

> -----Original Message-----
> From: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org]
> On Behalf Of Stephan Meißl
> Sent: 14 July 2016 11:57
> To: mapserver-users at lists.osgeo.org
> Subject: Re: [mapserver-users] Python MapScript via WSGI examples
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi Tom,
> 
> adding to Julien's response you could also replace
> `request.loadParams()` with
> `request.loadParamsFromURL(env['QUERY_STRING'])`.
> 
> As Julien said, key is that the environment variables are not set
> automatically.
> 
> cu
> Stephan
> 
> 
> On 07/14/2016 05:19 PM, Julien-Samuel Lacroix wrote:
> > Hi Tom,
> >
> > When I run your script, I get the following response:
> >
> >   This script can only be used to decode form results and
> >   should be initiated as a CGI process via a httpd server.
> >
> > This answer does not contain any content-type that can be stripped wit
> h
> > msIO_getStdoutBufferBytes(). That's why it returns None.
> >
> > Before your OWSRequest call, you need to set the Environment variable
> > that MapServer needs. Otherwise they are passed in the env variable an
> d
> > not to MapServer. Code to add:
> >
> >
> > # List of all environment variable used by MapServer
> > mapserv_env = [
> >  'CONTENT_LENGTH', 'CONTENT_TYPE', 'CURL_CA_BUNDLE',
> 'HTTP_COOKIE',
> >  'HTTP_HOST', 'HTTPS', 'HTTP_X_FORWARDED_HOST',
> 'HTTP_X_FORWARDED_PORT
> ',
> >  'HTTP_X_FORWARDED_PROTO', 'MS_DEBUGLEVEL',
> 'MS_ENCRYPTION_KEY',
> >  'MS_ERRORFILE', 'MS_MAPFILE', 'MS_MAPFILE_PATTERN',
> 'MS_MAP_NO_PATH',
> >  'MS_MAP_PATTERN', 'MS_MODE', 'MS_OPENLAYERS_JS_URL',
> 'MS_TEMPPATH',
> >  'MS_XMLMAPFILE_XSLT', 'PROJ_LIB', 'QUERY_STRING', 'REMOTE_ADDR',
> >  'REQUEST_METHOD', 'SCRIPT_NAME', 'SERVER_NAME', 'SERVER_PORT'
> > ]
> > for key in mapserv_env:
> >     if key in env:
> >         os.environ[key] = env[key]
> >     else:
> >         os.unsetenv(key)
> > request = mapscript.OWSRequest()
> >
> >
> > Best regards,
> > Julien
> >
> > On 16-07-13 12:55 PM, Kralidis, Tom (EC) wrote:
> >> Hi all: we are looking into updating our Python MapScript (CGI-based)
> >> wrappers
> >> to leverage WSGI, and are having integration issues as part of testin
> g.
> >>
> >> We are using 6.4.2 on Ubuntu 14.04.  See example in [1] (against
> >> any mapfile is fine).  Simple run with python ./mapscript-wsgi.py
> >> which makes
> >> the server available on localhost:8000 by default.
> >>
> >> Issues:
> >>
> >> - the value in
> >>
> https://gist.github.com/tomkralidis/9adbd4864c03647aa7eb4f96a3c33297#
> file-mapscript-wsgi-py-L18
> >> ends up being a Python None type for some reason when it should be a
> >> string of the content-type
> >> - issuing a, say, WMS 1.3.0 GetCapabilities request yields the
> >> venerable MapServer "This script can ...." default message, when I am
> >> expecting Capabilities XML
> >>
> >> Any ideas what I'm doing wrong here?
> >>
> >> ..Tom
> >>
> >> [1] https://gist.github.com/tomkralidis/9adbd4864c03647aa7eb4f96a3c33
> 297
> >> _______________________________________________
> >> mapserver-users mailing list
> >> mapserver-users at lists.osgeo.org
> >> http://lists.osgeo.org/mailman/listinfo/mapserver-users
> >>
> >
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.22 (GNU/Linux)
> 
> iQIcBAEBAgAGBQJXh7ZVAAoJEKNQXeNWi+qtf9UP/1k7tdKlqkLm2wZ3449qcY
> 5F
> f8c9OfudiF3UAcIM5+V6+MDMRYFBC4u55g7tsfXRp/iiL4IaDYL5S5xmCViGaEw
> K
> T3fcB+F1UsJ68q7QWRyrJwQW8CPXDACTnDppIGE4yspSxCQHubbrbDCNzvQh
> qlx2
> 7YcnqTTNghcPMM4AKg0etzH+9I73nYYzukiZe0ZGvI+g0caotEAdY/Xb5kb3GuzJ
> aWV4fgTJSgS/r0R6O1UP+I41jHEUrgqoT7qLNqdKOyv502YZ/EGwkclhnPQst2B
> q
> 1jFeNqsfvju4D3Ob/EGl4GnQEfptYqh+KwRmxeB+tW8kzRdIVD1D9R0MlbM5N
> C4d
> JHY1/4fpeBcFjbA+MVIWr2tbV7gDV4Mht/4lUszDNCUt055vV47sd+NNXl78+Fk
> 8
> lrdqbqtxJzKW0mKAsr44jmn65iMrqm+ts06iHTLPfKFkHL7kxqDWk8wIy8Xq6rG
> E
> 5c5cbHQOj6bXqlgZGxxcLq3kZu/Tpg1VOnD+DorpnVLrR7JOnDV+JDSaU7YCfhz
> I
> yV2WYbEGuJCZKEH7bLY/8oQ3XKCiH8+0a+RRU1efLjzCquLSCYXAOUc6pCPNzl
> rY
> JCV8VT6Fmnp/+brrCxCMgse39LWK8x9RuxSbi8UocFhDnmtbDgojA7xrzt/onq
> BJ
> 6Fzq/t4Wnl3ifjK1vjlK
> =Gj2e
> -----END PGP SIGNATURE-----
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users


More information about the MapServer-users mailing list