[mapserver-users] Python MapScript via WSGI examples

Julien-Samuel Lacroix jlacroix at mapgears.com
Thu Jul 14 08:19:22 PDT 2016


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 with 
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 and 
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 testing.
>
> 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/9adbd4864c03647aa7eb4f96a3c33297
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>

-- 
Julien-Samuel Lacroix
T: +1 418-696-5056 #202
Mapgears
http://www.mapgears.com/



More information about the MapServer-users mailing list