[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Address boundary error on POST QHttpMultiPart
From:       Šimon_Leitgeb <leitgeb.simon () gmail ! com>
Date:       2023-10-31 19:52:49
Message-ID: CAAFqbYY17hEgv9iO0fp9jKLSnJencRx-dE6CRtt8ipXJtAEwLQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello,
I'm currently working on an application that sends some requests using
PyQt, but multipart formdata post requests are giving me trouble.

Get requests and simple post requests (with just binary data as body) work
without any problems, but requests that contain QHttpMultiPart as body
crash Python with the following:
fish: Job 1, 'pipenv run python post.py' terminated by signal SIGSEGV
(Address boundary error)

I'm using PyQt5 with Python 3.11.5, but the same issue occurs in PyQt6 as
well.
You can find a minimal example attached, if anyone would like to test this
for themselves.

Any ideas why this program crashes?

All the best,
Simon Leitgeb

[Attachment #5 (text/html)]

<div dir="ltr">Hello,<br>I&#39;m currently working on an application that sends some \
requests using PyQt, but multipart formdata post requests are giving me \
trouble.<br><br>Get requests and simple post requests (with just binary data as body) \
work without any problems, but requests that contain QHttpMultiPart as body crash \
Python with the following:<br>fish: Job 1, &#39;pipenv run python post.py&#39; \
terminated by signal SIGSEGV (Address boundary error)<br><br>I&#39;m using PyQt5 with \
Python 3.11.5, but the same issue occurs in PyQt6 as well.<br>You can find a minimal \
example attached, if anyone would like to test this for themselves.<br><br>Any ideas \
why this program crashes?<br><br>All the best,<br>Simon Leitgeb<br></div>


["post.py" (text/x-python)]

#!/usr/bin/env python3

import sys
from PyQt5.QtCore import QUrl, QCoreApplication, QByteArray
from PyQt5.QtNetwork import (
    QNetworkAccessManager,
    QNetworkRequest,
    QNetworkReply,
    QHttpPart,
    QHttpMultiPart,
)


class Example:
    def __init__(self):
        self.network_manager = QNetworkAccessManager()
        self.multipart_post()

    def multipart_post(self):
        URL = "http://httpbin.org/post"
        body = QHttpMultiPart(QHttpMultiPart.ContentType.FormDataType)
        boundary = body.boundary()
        part = QHttpPart()
        part.setHeader(
            QNetworkRequest.KnownHeaders.ContentTypeHeader, "application/json"
        )
        part.setHeader(
            QNetworkRequest.KnownHeaders.ContentDispositionHeader,
            'form-data; name="test"',
        )
        data = QByteArray()
        data.append(b"test")
        part.setBody(data)
        body.append(part)
        request = QNetworkRequest(QUrl(URL))
        request.setHeader(QNetworkRequest.KnownHeaders.ContentTypeHeader, \
f'multipart/form-data; boundary={str(boundary, "utf-8")}')  \
self.network_manager.finished.connect(self.handle_reply)  response = \
self.network_manager.post(request, body)  print(response)

    def handle_reply(self, reply):
        print(reply.error())
        print(reply.readAll())
        QCoreApplication.quit()


def main():
    app = QCoreApplication([])
    ex = Example()
    sys.exit(app.exec())


if __name__ == "__main__":
    main()



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic