1
當我嘗試下載一個文件在Python 3.3.2與urllib.request.urlretrieve功能,我得到以下錯誤:Python3 - urllib.request裏權限被拒絕
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Python33\lib\site-packages\downloader.py", line 17, in startdownload
urllib.request.urlretrieve(url, file, reporthook)
File "C:\Python33\lib\urllib\request.py", line 191, in urlretrieve
tfp = open(filename, 'wb')
PermissionError: [Errno 13] Permission denied: '.\\tmp'
我試圖挽救我的桌面上的dir tmp文件。我在模塊「downloader.py」中使用以下代碼:
def download(url, file):
import urllib.request, tkinter, os, time
from tkinter import ttk
def reporthook(blocknum, blocksize, totalsize):
readsofar = blocknum*blocksize
percent = readsofar * 1e2/totalsize
GUI.title(str(int(percent)) + "% done")
PROGRESS["value"] = percent
PROGRESS.update()
def startdownload():
BUTTON.destroy()
for y in range(70, 40, -1):
time.sleep(0.1)
GUI.geometry("500x"+str(y))
GUI.update()
urllib.request.urlretrieve(url, file, reporthook)
GUI.destroy()
GUI = tkinter.Tk()
GUI.resizable(0,0)
GUI.title("Click the download button to start downloading!")
GUI.geometry("500x70")
PROGRESS = ttk.Progressbar(GUI, length=480)
PROGRESS.place(x=10, y=10)
BUTTON = ttk.Button(GUI, text="start download", command=startdownload)
BUTTON.place(x=200, y=40)
GUI.mainloop()
我不知道如何給python下載文件的權限。或者在代碼中出現錯誤?
謝謝你的幫助!
---編輯---
我注意到,對一切工作只是正常使用Python 2.5!那是什麼意思! 請幫忙:-)
看起來像你的程序保存到用戶的限制文件夾。檢查您是否有權訪問「文件名」處的位置。請查看[文檔](http://docs.python.org/3.0/library/urllib.request.html#urllib.request.urlretrieve)以獲取更多的說明。 –
@AshishNitinPatil我如何賦予Python訪問文件/目錄的權限?我注意到另一件事情:在Python 2.5中,一切正常與urllib.urlretrieve函數。請幫忙:) – crey4fun
我現在沒有線索。抱歉。另外,我說的是*「maybe」* –