I want to send http request in a QGIS plugin using PyQt. I found in this post working syntaxes to do so, but something odd occurs.
The script given in the question works both in the console and in my plugin. But the script given as an answer by German Carrillo, technically better, works when executed in QGIS python console, but doesn't as soon as it is integrated in a plugin.
So this works in the console, but doesn't when integrated in a plugin script :
from PyQt4.QtCore import QUrl
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
def request_download(manager):
url = QUrl("https://www.facebook.com")
request = QNetworkRequest(url)
manager.get( request )
def handle_download(reply):
print reply.readAll()
manager = QNetworkAccessManager()
manager.finished.connect( handle_download )
request_download(manager)
Considering the logs I have put in my script to locate the issue, it appears the handle_dowload function is never called. So it means the QNetworkAccessManager doesn't send his finished signal.
Is there known reasons why something would work in the console but not in a plugin ?
handle_download
take areply
attribute?pushButton.clicked.connect(function)
- if function is declared asfunction(self)
, additional argument won't fit here. where do you have thesemanager
command in the plugin?