I'm going to answer to myself. <br>I found a solution, and it was really simple!<br><br>Working code:<br><br><br>class Async(QThread):<br> def run(self):<br> self.jar = QNetworkCookieJar()<br> self.manager = QNetworkAccessManager()<br>
self.manager.setCookieJar(self.jar)<br> self.manager.finished.connect(self.downloadFinished)<br> self.manager.authenticationRequired.connect(self.authenticationRequired)<br> self.request = QNetworkRequest(self.url)<br>
self.request.setRawHeader("User-Agent", self.userAgent)<br> self.reply = self.manager.get(self.request)<br> self.reply.downloadProgress.connect(self.progressCallback)<br> self.exec_()<br> <br> def download(self, url, userAgent = "Wget/1.12 (linux-gnu)", user = "", password = ""):<br>
self.url = QUrl(url)<br> self.userAgent = userAgent<br> self.user = user<br> self.password = password<br> self.returnData = None<br> self.moveToThread(self) ### <------ Added line that fixes the problem!<br>
self.start()<br><br> def authenticationRequired(self, reply, authenticator):<br> authenticator.setUser(self.user)<br> authenticator.setPassword(self.password)<br><br> def progressCallback(self, done, total):<br>
self.emit(QtCore.SIGNAL('progress(int, int)'), done, total)<br><br> def downloadFinished(self, reply):<br> print "dfinished"<br> self.redirect = reply.attribute(QNetworkRequest.RedirectionTargetAttribute).toUrl()<br>
if not self.redirect.isEmpty():<br> self.request = QNetworkRequest(self.redirect)<br> self.request.setRawHeader("User-Agent", self.userAgent)<br> self.reply = self.manager.get(self.request)<br>
self.reply.downloadProgress.connect(self.progressCallback)<br> else:<br> self.emit(QtCore.SIGNAL('finished(PyQt_PyObject)'), str(self.reply.readAll()))<br> self.quit()<br><br><br>-- <br>Alexander Nestorov<br>