【问题标题】:I need to download the image from URL and save into the folder in python 3.7我需要从 URL 下载图像并保存到 python 3.7 的文件夹中
【发布时间】:2020-01-06 12:54:25
【问题描述】:

它在本地机器上运行完美,但是当我将相同的代码上传到 AWS 服务器时,它只下载了 1kb 的图像并且它不可读?我需要来自 URL 的整个图像。请告诉我如何解决此问题?

print('Download Starting...')

url = 'https://hotpoptoday.com/wp-content/uploads/2019/12/9062079d.jpg'

req = requests.get(url, stream=True)


with open("9062079d.jpg",'wb') as output_file:
    for chunk in req.iter_content(chunk_size=1025):
        if chunk:
            output_file.write(chunk)

print('Download Completed!!!')

【问题讨论】:

  • 这里没有任何神奇或特定于 AWS 或请求的东西应该有所作为。你有足够的可用空间吗?你如何确定你只有 1kb 的数据?你知道它是第一个 1kb 还是其他部分?顺便说一句,您使用的是非常规的块大小。您是否尝试过我在How to download image using requests 的回答中提出的任何其他建议?

标签: python python-3.x python-requests


【解决方案1】:

就这样使用

urllib.urlretrieve(url_to_your_image, "folders_name/saved_image.jpg")

如果你想在保存前创建文件夹

os.mkdir('folder_name')

【讨论】:

    猜你喜欢
    • 2019-10-31
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多