[Pywps-devel] problem with CGI and Wget
Jorge de Jesus
jorge.de-jesus at jrc.it
Wed Jan 21 17:12:29 CET 2009
Hi to all
I had some problems, with the WPS service
1. I made the following command:
wget -nv -q -O - --post-file=dummyprocess.xml
http://localhost/cgi-bin/wps.py <http://localhost/cgi-bin/wps.py>
But nothing worked, actualy the sysin (in the script wps.py) used to
catch the POST file was completely empty. It took me a while but I
discovered that wget (1.11.4) was sending the header with:
CONTENT_TYPE = application/x-www-form-
urlencoded
CONTENT_LENGTH = 0
I then made a simple html form file submitter to send the XML file.
<html><body>
<form enctype="multipart/form-data" action="../cgi-bin/wps.py"
method="post">
<p>File: <input type="file" name="file"></p>
<p><input type="submit" value="Upload"></p>
</form>
</body></html>
Actually the problem is with the content type that SHOULD be as
multipart/form-data
I didnt found any information on this.....does anyone knows something ?!
2. Request problem and XML parsing
After implementing the above, the XML parser crashed.... it seems that
when you do something like this:
>cat dummyrequest.xml | wps.py
Everything is fine, the problem is that when using CGI, the sysin
contains the content headers and footer
-----------------------------101407164111186312061014035381
Content-Disposition: form-data; name="file"; filename="dummyrequest.xml"
Content-Type: text/xml
<wps:Execute service="WPS" version="1.0.0"
xmlns:ows="http://www.opengis.net/ows/1.1
<http://www.opengis.net/ows/1.1>"
xmlns:wps="http://www.opengis.net/wps/1.0.0
<http://www.opengis.net/wps/1.0.0>"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
<http://www.w3.org/2001/XMLSchema-instance>"
xsi:schemaLocation="http://www.opengis.net/wps/1.0.0
<http://www.opengis.net/wps/1.0.0>
http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd
<http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd>"><ows:Identifier>dummyprocess</ows:Identifier><wps:DataInputs><wps:Input>
:
:
</wps:Execute>
-----------------------------101407164111186312061014035381--
3. Code to solve the problems
The first problem was solved by adding the following to the wps.py (I
att. the new file in the email)
try:
if int(os.environ["CONTENT_LENGTH"]):
parser = Post(self)
parser.parse(sys.stdin)
else:
raise Exceptions.NoApplicableCode("Couldn't get the POST
request or empty POST request")
except:
parser = Post(self)
parser.parse(sys.stdin)
On the post.py file I had a simple rsplit algorithm that splits the
strings by "\n\r" and then assumes that the XML request should be the
biggest string:
# read the document
if maxFileSize > 0:
inputXmlRaw = file.read(maxFileSize)
if file.read() != "":
raise self.wps.exceptions.FileSizeExceeded()
else:
inputXmlRaw = file.read()
#The input XML may have the header from the HTTP-POST request,
therefore it needs to be clean
rawStringList=inputXmlRaw.rsplit("\r\n")
inputXml=rawStringList[0]
for item in rawStringList:
if len(item)>len(inputXml):
inputXml=item
# make DOM from XML
Maybe this could be done in a more elegant way......
Best Jorge
--
Ph.D. Jorge Samuel Mendes de Jesus
European Commission (EC)
Joint Research Centre Directorate (DG JRC)
Institute for Environment and Sustainability (IES)
TP 441, Via Fermi 1
21020 Ispra (VA)
Italy
Phone: +39 0332 78 3536
Fax: +39 0332 78 5466
http://rem.jrc.ec.europa.eu
"The views expressed are purely those of the writer and may not in any circumstances be regarded as stating an official position of the European Commission"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wald.intevation.org/pipermail/pywps-devel/attachments/20090121/0033703d/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wps.py
Type: text/x-python
Size: 8279 bytes
Desc: not available
Url : http://lists.wald.intevation.org/pipermail/pywps-devel/attachments/20090121/0033703d/wps.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Post.py
Type: text/x-python
Size: 6440 bytes
Desc: not available
Url : http://lists.wald.intevation.org/pipermail/pywps-devel/attachments/20090121/0033703d/Post.py
More information about the Pywps-devel
mailing list