连接到 ftp 并下载文件
connect to ftp and download file
我正在尝试从 ftp 下载特定文件,但在尝试连接
时出现错误
import ftplib
url = 'ftp://ftp.ensemblgenomes.org/pub/release-41/bacteria//fasta/bacteria_176_collection/_bacillus_aminovorans/cdna/'
ftp = ftplib.FTP(url)
我得到的错误:UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)
url = 'ftp://ftp.ensemblgenomes.org/pub/release-41/bacteria//fasta/bacteria_176_collection/_bacillus_aminovorans/cdna/'
ftp = ftplib.FTP(url)
来自the documentation of ftplib:
class ftplib.FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None)
Return a new instance of the FTP class. When host is given, the method call connect(host) is made.
换句话说:第一个参数应该只是主机名,而不是 URL 和 protocol://host/path
。如果您想连接到服务器并使服务器更改为特定路径,则需要分步执行:
ftp = ftplib.FTP('ftp.ensemblgenomes.org','ftp','user@example.com')
ftp.cwd('/pub/release-41/bacteria//fasta/bacteria_176_collection/_bacillus_aminovorans/cdna/')
我正在尝试从 ftp 下载特定文件,但在尝试连接
时出现错误import ftplib
url = 'ftp://ftp.ensemblgenomes.org/pub/release-41/bacteria//fasta/bacteria_176_collection/_bacillus_aminovorans/cdna/'
ftp = ftplib.FTP(url)
我得到的错误:UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)
url = 'ftp://ftp.ensemblgenomes.org/pub/release-41/bacteria//fasta/bacteria_176_collection/_bacillus_aminovorans/cdna/'
ftp = ftplib.FTP(url)
来自the documentation of ftplib:
class ftplib.FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None)
Return a new instance of the FTP class. When host is given, the method call connect(host) is made.
换句话说:第一个参数应该只是主机名,而不是 URL 和 protocol://host/path
。如果您想连接到服务器并使服务器更改为特定路径,则需要分步执行:
ftp = ftplib.FTP('ftp.ensemblgenomes.org','ftp','user@example.com')
ftp.cwd('/pub/release-41/bacteria//fasta/bacteria_176_collection/_bacillus_aminovorans/cdna/')