Thank you Alessandro, just filed the bug:
https://github.com/qgis/QGIS/issues/46989
I'm not allowed to assign it to you, so could you please do that
yourself. And if you need any help from me just let me know.
Kind regards,
Raymond
On 24-01-2022 11:11, Alessandro Pasotti wrote:
Hi Raymond,
can you please file a bug and assign it to me, I'll have a look.
On Sat, Jan 22, 2022 at 1:32 PM Raymond Nijssen <[email protected]
<mailto:[email protected]>> wrote:
Dear all,
One of my plugins stopped working in QGIS master, because some of the
requests seem invalid. I spent quite some time on debugging but cannot
find the problem.
This script runs in 3.22.3 but not ion 3.23. It uploads an xml file
to a
validation service. It should print: {'successful': True, 'errors': [],
'warnings': []}
Anyone a clue? I'm feeling that the best way would be using the
QgsBlockingNetworkRequest post() function but that does not seem to
work
with a QHttpMultiPart variable.
Thanks!
Raymond
import json
manager = QgsNetworkAccessManager.instance()
url = QUrl('https://connect.aerius.nl/api/v7/utility/validate
<https://connect.aerius.nl/api/v7/utility/validate>')
request = QNetworkRequest(url)
multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType)
file_parts = []
gml_fn =
'/home/raymond/terglobo/projecten/aerius/202007_calc_input_plugin/demodata/test_20220121/test_kort.gml'
file_parts.append({'name': 'filePart', 'file_name': gml_fn,
'file_type':
'application/gml+xml'})
for fp in file_parts:
file = QFile(fp['file_name'])
file_part = QHttpPart()
file_part.setHeader(QNetworkRequest.ContentTypeHeader,
QVariant(fp['file_type']))
name = fp['name']
file_part.setHeader(QNetworkRequest.ContentDispositionHeader,
QVariant(f'form-data; name="{name}";
filename="{QFileInfo(file).fileName()}"'))
file.open(QIODevice.ReadOnly)
file_part.setBodyDevice(file)
file.setParent(multi_part)
multi_part.append(file_part)
# This line already fires an invalid request in qgis 3.23:
reply = manager.post <http://manager.post>(request, multi_part)
# In qgis 3.22 the request is ok. The rest of the code will wait for
the
json
# reply and display it.
# make request blocking
loop = QEventLoop()
reply.finished.connect(loop.quit)
loop.exec_()
bstr = reply.readAll()
result_dict = json.loads(bytes(bstr))
print(result_dict)
_______________________________________________
QGIS-Developer mailing list
[email protected] <mailto:[email protected]>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
<https://lists.osgeo.org/mailman/listinfo/qgis-developer>
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
<https://lists.osgeo.org/mailman/listinfo/qgis-developer>
--
Alessandro Pasotti
QCooperative: www.qcooperative.net <https://www.qcooperative.net>
ItOpen: www.itopen.it <http://www.itopen.it>
_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer