Python 3 ftplib 错误“名称或服务未知”

Sid*_*d24 3 python sockets ftp ftplib

我正在尝试使用 Python 3 的 ftplib 库从 FTP 服务器下载文件。

这是相关的代码-

ftp = ftplib.FTP("ftp://library.daisy.org:21/User_****/Wise & Otherwise-22.zip") 
ftp.login("xxxxx", "xxxxxxx") 
ftp.cwd(path)
ftp.retrbinary("RETR " + filename, open(filename, 'wb').write)
ftp.quit()
Run Code Online (Sandbox Code Playgroud)

当我尝试运行脚本时出现以下错误 -

ftp = ftplib.FTP("ftp://library.daisy.org:21/User_****/Wise & Otherwise-22.zip") 
ftp.login("xxxxx", "xxxxxxx") 
ftp.cwd(path)
ftp.retrbinary("RETR " + filename, open(filename, 'wb').write)
ftp.quit()
Run Code Online (Sandbox Code Playgroud)

一些注意事项——

  1. 我有正确的 URL 和凭据
  2. 我在代理服务器后面

Mar*_*ryl 6

构造函数的host参数,FTP顾名思义,只接受一个主机名,比如library.daisy.org. 您正在传递一个完整的 URL。

这是对的:

ftp = ftplib.FTP("library.daisy.org")
Run Code Online (Sandbox Code Playgroud)

完整路径指向RETR命令的参数:

ftp.retrbinary("RETR User_****/Wise & Otherwise-22.zip", open(filename, 'wb').write)
Run Code Online (Sandbox Code Playgroud)

当您通过代理连接时,您也必须满足这一点。

这里有很多问题涉及该部分。但是您没有告诉我们您使用的是哪种代理,所以我不能更具体。