Chained Execute request: "POST data should be bytes or an iterable of bytes. It cannot be of type str."
Description
I'm trying to chain Execute requests (smoothing of a time series).
PyWPS seems to interpret the contents of the <wps:Body> as an str and use this as the body of the subsequent POST request. However, urllib refuses to use this str as the body and throws this exception instead:
POST data should be bytes or an iterable of bytes. It cannot be of type str., description:
Traceback (most recent call last):
File "/home/bossie/PycharmProjects/list-tsa-service/env/lib/python3.5/site-packages/pywps/app/Service.py", line 402, in href_handler
(reference_file, reference_file_data) = _openurl(datain)
File "/home/bossie/PycharmProjects/list-tsa-service/env/lib/python3.5/site-packages/pywps/app/Service.py", line 622, in _openurl
reference_file = urlopen(url=href, data=data)
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 464, in open
req = meth(req)
File "/usr/lib/python3.5/urllib/request.py", line 1183, in do_request_
raise TypeError(msg)
TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
This is the request I'm trying to send:
<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>smooth</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>timeseries</ows:Identifier>
<wps:Reference mimeType="text/xml; subtype=gml/3.1.1" xlink:href="http://localhost:5000/tsa/wps" method="POST">
<wps:Body>
<wps:Execute version="1.0.0" service="WPS">
<ows:Identifier>timeseries</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>product_id</ows:Identifier>
<wps:Data>
<wps:LiteralData>BIOPAR_FAPAR_V2_GLOBAL</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>feature</ows:Identifier>
<wps:Data>
<wps:ComplexData mimeType="application/vnd.geo+json">
<![CDATA[{
"type": "Feature",
"id": "dza_bnd_admin1_a_gaul.37",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-0.1877083329999891,
35.124645233000024
],
[
-0.1652933959999814,
35.12269592299998
],
[
-0.1352777769999989,
35.12360382100002
],
[
-0.0005555559999948,
35.05944061299999
],
[
-0.1877083329999891,
35.124645233000024
]
]
]
]
}
}]]>
</wps:ComplexData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput mimeType="text/xml; subtype=gml/3.1.1">
<ows:Identifier>timeseries</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
</wps:Body>
</wps:Reference>
</wps:Input>
</wps:DataInputs>
</wps:Execute>
Environment
- operating system: Ubuntu 16.04
- Python version: 3.5.2
- PyWPS version: 4.0.0
- source/distribution
- [ ] git clone
- [ ] Debian
- [x] PyPI
- [ ] zip/tar.gz
- [ ] other (please specify):
- web server
- [ ] Apache/mod_wsgi
- [ ] CGI
- [x] other (please specify): Flask development server
Hi,
current master branch of PyWPS uses the requests library instead of urlopen, which seems to be working fine .. could be please test your usecase with the master branch?
Happened to me too. As jachym said it was fixed (so the issue is no longer relevant) but since then the PyPI haven't been updated. so fixing #353 I've just opened should do the trick