どのようにしてFTP urlを開いてファイルにダウンロードできますか?私はルックスにこのような何かしようとしている:Python open FTP urlとファイルに書き込む
from contextlib import closing
from urllib.request import urlopen
url = 'ftp://whatever.com/file.txt'
target_path = 'file.txt'
with closing(urlopen(url)) as source:
with open(target_path, 'wb') as target:
target.write(source)
しかし、これは次のエラーで失敗します。
TypeError: 'addinfourl' does not support the buffer interface
することは、この作品を作るための任意の簡単な方法はありますか?特にファイルを展開する際にファイルを展開するように拡張したいのですが?
「クローズ」とは何ですか? FTP URLの内容と同じにしたいと思うでしょうか? – holdenweb
お詫び申し上げます、私はうさぎのコードスニペットを投稿しました。私はインポートステートメントを追加しました。 –