Updated to client for python 3

This commit is contained in:
Adolfo Gómez García 2020-07-20 13:15:00 +02:00
parent 2fbdef1739
commit a648f5686e
2 changed files with 13 additions and 19 deletions

View File

@ -30,9 +30,6 @@
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
# pylint: disable=c-extension-no-member
from __future__ import unicode_literals
import sys
import webbrowser
import json
@ -118,7 +115,6 @@ class UDSClient(QtWidgets.QMainWindow):
def cancelPushed(self):
self.close()
@QtCore.pyqtSlot()
def updateAnim(self):
self.anim += 2
if self.anim > 99:
@ -139,12 +135,10 @@ class UDSClient(QtWidgets.QMainWindow):
self.ui.progressBar.invertedAppearance = False
self.animTimer.stop()
@QtCore.pyqtSlot()
def getVersion(self):
self.req = RestRequest('', self, self.version)
self.req.get()
@QtCore.pyqtSlot(dict)
def version(self, data):
try:
self.processError(data)
@ -160,14 +154,12 @@ class UDSClient(QtWidgets.QMainWindow):
self.getTransportData()
except RetryException as e:
self.ui.info.setText(six.text_type(e))
self.ui.info.setText(str(e))
QtCore.QTimer.singleShot(1000, self.getVersion)
except Exception as e:
self.showError(e)
@QtCore.pyqtSlot()
def getTransportData(self):
try:
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
@ -176,8 +168,6 @@ class UDSClient(QtWidgets.QMainWindow):
logger.exception('Got exception on getTransportData')
raise e
@QtCore.pyqtSlot(dict)
def transportDataReceived(self, data):
logger.debug('Transport data received')
try:
@ -274,6 +264,7 @@ def approveHost(hostName, parentWindow=None):
if __name__ == "__main__":
logger.debug('Initializing connector')
# Initialize app
app = QtWidgets.QApplication(sys.argv)

View File

@ -31,13 +31,10 @@
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
# pylint: disable=c-extension-no-member,no-name-in-module
from __future__ import unicode_literals
import json
import urllib
import six
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtCore import QObject, QUrl, QSettings
from PyQt5.QtCore import Qt
@ -60,8 +57,16 @@ class RestRequest(QObject):
super(RestRequest, self).__init__()
# private
self._manager = QNetworkAccessManager()
try:
if os.path.exists('/etc/ssl/certs/ca-certificates.crt'):
pass
# os.environ['REQUESTS_CA_BUNDLE'] = '/etc/ssl/certs/ca-certificates.crt'
except Exception:
pass
if params is not None:
url += '?' + '&'.join('{}={}'.format(k, urllib.parse.quote(six.text_type(v).encode('utf8'))) for k, v in params.items())
url += '?' + '&'.join('{}={}'.format(k, urllib.parse.quote(str(v).encode('utf8'))) for k, v in params.items())
self.url = QUrl(RestRequest.restApiUrl + url)
@ -79,14 +84,12 @@ class RestRequest(QObject):
try:
if reply.error() != QNetworkReply.NoError:
raise Exception(reply.errorString())
#data = six.text_type(reply.readAll())
data = bytes(reply.readAll())
#data = data.encode("utf-8")
data = json.loads(data)
except Exception as e:
data = {
'result': None,
'error': six.text_type(e)
'error': str(e)
}
self.done.emit(data)
@ -97,7 +100,7 @@ class RestRequest(QObject):
settings = QSettings()
settings.beginGroup('ssl')
cert = errors[0].certificate()
digest = six.text_type(cert.digest().toHex())
digest = str(cert.digest().toHex())
approved = settings.value(digest, False)