Could you please tell me why a GET request to a last.fm web service
URL returns a different result whether I call it from a browser or
from a QNetworkAccessManager?

A specific example would be the following URL:

http://ws.audioscrobbler.com/2.0/?album=American+IV%3A+The+Man+Comes+Around&format=json&autocorrect=1&artist=Johnny+Cash&mbid=261de123-7315-4a2f-8c40-3dad9092313e&api_key=295a01cfa65f9e521bdd2cc3c36d7c89&method=album.getinfo

Pasting it into Google Chrome's address bar produces the expected
album info page.

However, calling the same URL with a QNetworkRequest to a
QNetworkAccessManager returns a response with the following body:

{"error":6,"message":"Album not found"}

Attached is a short program demonstrating this.

Obviously, the program is not making the call correctly. How should I
correct it?
#!/usr/bin/env python2.6
 
from sip import setapi
 
setapi("QDate", 2)
setapi("QDateTime", 2)
setapi("QTextStream", 2)
setapi("QTime", 2)
setapi("QVariant", 2)
setapi("QString", 2)
setapi("QUrl", 2)
 
from PyQt4.QtCore import QUrl 
from PyQt4.QtGui import QApplication, QMainWindow
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
from sys import argv
 
def main():
    app = QApplication(argv)
    main = MainWindow()
    main.show()
    exit(app.exec_())
 
class MainWindow(QMainWindow):
 
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.manager = QNetworkAccessManager(self)
 
        request = QNetworkRequest()
 
        request.setUrl(QUrl('http://ws.audioscrobbler.com/2.0/?album=American+IV%3A+The+Man+Comes+Around&format=json&autocorrect=1&artist=Johnny+Cash&mbid=261de123-7315-4a2f-8c40-3dad9092313e&api_key=295a01cfa65f9e521bdd2cc3c36d7c89&method=album.getinfo'))
        reply = self.manager.get(request)
        reply.finished.connect(self.replyFinished)
 
    def replyFinished(self):
        reply = self.sender()
        raw = reply.readAll()
        print raw
        reply.deleteLater()
 
 
if __name__ == "__main__":
   main()
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to