我收到这个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "C:/Users/Marc/Documents/Programmation/Python/Llamachat/Llamachat/Llamachat.py", line 32, in download
with open(place_to_save, 'wb') as file:
PermissionError: [Errno 13] Permission denied: '/goodbye.txt'
运行时:
def download():
# get selected line index
index = films_list.curselection()[0]
# get the line's text
selected_text = films_list.get(index)
directory = filedialog.askdirectory(parent=root,
title="Choose where to save your movie")
place_to_save = directory + '/' + selected_text
print(directory, selected_text, place_to_save)
with open(place_to_save, 'wb') as file:
connect.retrbinary('RETR ' + selected_text, file.write)
tk.messagebox.showwarning('File downloaded',
'Your movie has been successfully downloaded!'
'\nAnd saved where you asked us to save it!!')
有人能告诉我我做错了什么吗?谢谢
规格:Python 3.4.4 x86 Windows 10 x64
在Windows上实现管理员execution
权限基本上有三种主要方法。
cmd.exe
以管理员身份运行python
可执行文件的权限(不推荐)cmd.exe
as and admin由于在Windows中没有sudo
命令,您必须以管理员身份运行终端(cmd.exe
)以达到相当于sudo
的权限级别。你可以这两种方式:
cmd.exe
找到C:\Windows\system32
右键单击它
选择Run as Administrator
然后它将在C:\Windows\system32
目录中打开命令提示符
前往您的项目目录
运行你的程序alt
和ctrl
之间)+ X
。
将出现包含各种管理员任务的小弹出列表。
选择Command Prompt (Admin)
前往您的项目目录
运行你的程序通过这样做,您作为管理员运行,所以这个问题不应该持续存在
python.exe
创建快捷方式Properties
由"C:\path_to\python.exe" C:\path_to\your_script.py"
提供的delphifirst提供的答案
这是一种可能性,但我强烈反对你这样做。
它只涉及找到python
可执行文件并将其设置为每次都以管理员身份运行。可能并且可能会导致文件创建(它们只是管理员)或可能需要不是管理员运行的模块的问题。
更改要保存的目录的权限,以便所有用户都具有读写权限。
在使用Pycharm的Windows机器上发生了这种情况。
修复:右键单击PyCharm应用程序并以管理员身份运行它。
确保首先关闭您尝试写入的文件。
问题可能出在您要打开的文件的路径中。尝试并打印路径,看看它是否正常我有类似的问题
python
但添加此代码后:
def scrap(soup,filenm):
htm=(soup.prettify().replace("https://","")).replace("http://","")
if ".php" in filenm or ".aspx" in filenm or ".jsp" in filenm:
filenm=filenm.split("?")[0]
filenm=("{}.html").format(filenm)
print("Converted a file into html that was not compatible")
if ".aspx" in htm:
htm=htm.replace(".aspx",".aspx.html")
print("[process]...conversion fron aspx")
if ".jsp" in htm:
htm=htm.replace(".jsp",".jsp.html")
print("[process]..conversion from jsp")
if ".php" in htm:
htm=htm.replace(".php",".php.html")
print("[process]..conversion from php")
output=open("data/"+filenm,"w",encoding="utf-8")
output.write(htm)
output.close()
print("{} bits of data written".format(len(htm)))
它工作得很好
这里的问题是你的用户没有正确的nofilenametxt=filenm.split('/')
nofilenametxt=nofilenametxt[len(nofilenametxt)-1]
if (len(nofilenametxt)==0):
filenm=("{}index.html").format(filenm)
来打开文件这意味着你需要在运行该命令之前为你的python ide授予一些管理权限。
由于您是Windows用户,您只需右键单击python ide =>选择选项'以管理员身份运行'然后运行您的命令。
如果您使用命令行来运行代码,请执行相同操作以使用管理员权限打开命令提示符。
我遇到了类似的问题。我在Windows上使用Anaconda,我按如下方式解决:1)从开始菜单中搜索“Anaconda提示”2)右键单击并选择“以管理员身份运行”3)按照安装步骤操作...
这会处理权限问题
仔细检查并确保您尝试写入的文件未打开,或者后台的某些程序未保留此文件/数据。这对我来说是个问题。
PermissionError:[Errno 13]权限被拒绝:
我在使用excel时遇到了上述错误,我的excel已打开,然后我关闭并尝试运行我的代码。它对我有用。
您的文件必须是开放的。关闭您的文件并再次运行代码,它应该工作。