Exemple #1
0
    def slot_reply_finished(self, data: QNetworkReply):

        self._reply = data
        self._text = data.readAll()
        self._string = bytes(self._text).decode()
        self._status_code = data.attribute(
            QNetworkRequest.HttpStatusCodeAttribute)
        self._save_header(data.rawHeaderPairs())

        if self.content_type() == 'json':
            if len(self._string):
                self._json = json.loads(self._string)
        else:
            self._json = None

        if self._status_code >= 400:
            print(self._string)

        self.sig_ended.emit(True)
        data.deleteLater()
Exemple #2
0
 def from_reply(cls, reply: QtNetwork.QNetworkReply) -> 'Response':
     """Slowly populates a new Response object with data from the request."""
     r = cls()
     
     # Signal mapping
     reply.metaDataChanged.connect(functools.partial(r._insert_headers, reply.rawHeaderPairs()))
     reply.redirected.connect(r._insert_url)
     reply.error.connect(r._update_code)
     reply.error.connect(functools.partial(r._update_error_string, reply.errorString()))
     
     # Wait until the request is finished before continuing
     signals.wait_for_signal(reply.finished)
     
     # Strip the remaining data from the reply, then mark it for deletion
     r._from_reply(reply)
     
     reply.close()
     reply.deleteLater()
     
     # Return the object
     return r