【发布时间】:2021-11-04 08:27:37
【问题描述】:
我想知道是否可以直接使用 python 将图像从链接保存到 ftp 服务器,而无需将它们下载到笔记本电脑然后将它们上传到 ftp,我尝试使用 ftplib 和请求但没有工作,并抛出此错误,
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 我尝试了 encoding="utf8" 和错误忽略选项,但没有工作
import requests
from ftplib import FTP as tp
url = "https://im0-tub-com.yandex.net/i?id=5fda7c40cfa53d048d169908bbbd7cb6&n=13"
rq = requests.get(url).content
ftp = tp('host','username','password)
ftp.cwd("www")
with open(rq,'rb') as f:
ftp.storbinary("STOR "+"name.webp",f)
ftp.quit()
【问题讨论】:
-
如果可行,此代码将在上传到 FTP 之前将文件下载(到内存)。这是无法避免的。
-
tnx man 你节省了我的时间@Martin Prikryl