IOError: [Errno 2] No such file or directory

家住魔仙堡 提交于 2019-12-01 11:21:04

You're trying to open a file located in path, but not including that path, which tries to open the file in the current working path of your Python script. For example, if you run the script from /home/user/script.py, while your torrents are in /home/user/torrents. When you do open(file, 'rb') you are doing /home/user/charlie.torrent as opposed to /home/user/torrents/charlie.torrent. Try replacing with open(file, 'rb') with with open(os.path.join(path, file), 'rb').

You could also change the directory you are currently in to path.

...
dirs = os.listdir(path)
os.chdir(path)
for file in dirs:
...

That should work also.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!