mardi 21 avril 2015

errno 13 permission denied Pyththon QT

I followed a QT tutorial and now my end product doesn't work and exits with an errno 13 access denied. The program accepts a url to a file, as a string and a save location as a string. When the download button is pressed the error occurs. I am in a windows enviroment.

    import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import urllib.request


class Downloader(QDialog):
    def __init__(self):
        QDialog.__init__(self)

        layout = QVBoxLayout()

        self.url = QLineEdit()
        self.save_location = QLineEdit()
        progress = QProgressBar()
        download = QPushButton("Download")

        self.url.setPlaceholderText("URL")
        self.save_location.setPlaceholderText("File Save Location")

        progress.setValue(0)
        progress.setAlignment(Qt.AlignCenter)

        layout.addWidget(self.url)
        layout.addWidget(self.save_location)
        layout.addWidget(progress)
        layout.addWidget(download)

        self.setLayout(layout)

        self.setWindowTitle("Downloader")
        self.setFocus()

        # Connect Button press on Download to the download method.
        download.clicked.connect(self.download)

    def download(self):
        url = self.url.text()
        save_location = self.save_location.text()
        urllib.request.urlretrieve(url, save_location, self.report)

    def report(self, blocknum, blocksize, totalsize):
        read = blocknum * blocksize
        if totalsize > 0:
            percent = read * 100 / totalsize
            self.progress.setValue(int(percent))

app = QApplication(sys.argv)
dl = Downloader()
dl.show()
status = app.exec_()
sys.exit(status)

Aucun commentaire:

Enregistrer un commentaire