def on_received_response(self, reply: QNetworkReply):
        if reply.error() != QNetworkReply.NoError:
            error_msg = "Unable to create new print share: {}".format(reply.errorString())
            logging.error(error_msg)
            app_settings.app_data_writer.signals.exchange_share_failed.emit(error_msg)
            return

        share_location = reply.rawHeader(QByteArray(bytes("Location", encoding="utf-8")))
        app_settings.app_data_writer.signals.exchange_share_created.emit(share_location.data().decode())
        reply.deleteLater()
        self.buffer.close()
Beispiel #2
0
    def gotResponse(self, QNetworkReply):

        try:
            status = QNetworkReply.attribute(
                QNetworkRequest.HttpStatusCodeAttribute)
        except Exception as e:
            log('[e] http/yaml error: %s' % str(e))
            self.updatesLabel.setText('Error')
            return

        if status != 200:
            self.updatesLabel.setText('Network error: ' + str(status))

            try:
                for h in (QNetworkReply.rawHeaderList()):
                    log('[w] %s: %s' % (str(
                        h, 'utf-8'), str(QNetworkReply.rawHeader(h), 'utf-8')))
            except Exception as e:
                log('[e]: %s' % str(e))

            return

        try:
            response = QNetworkReply.readAll()
            response = str(response, 'utf-8')
            ver = safe_load(response)
        except Exception as e:
            log('[e] http/yaml error: %s' % str(e))
            self.updatesLabel.setText('error')
            return

        if ver is None:
            self.updatesLabel.setText('<network error>')
            return

        if 'version' in ver and 'date' in ver:
            verStr = 'Last published version is %s, build %s.' % (
                ver['version'], ver['date'])
            self.updatesLabel.setText(verStr)