简体   繁体   English

我需要从 URL 下载图像并保存到 python 3.7 中的文件夹中

[英]I need to download the image from URL and save into the folder in python 3.7

It's working perfect on local machine but when I upload the same code into the AWS server, its downloading only 1kb of image and its not readable?它在本地机器上运行良好,但是当我将相同的代码上传到 AWS 服务器时,它只下载 1kb 的图像并且不可读? I need the whole image from URL.我需要来自 URL 的整个图像。 Please let me know how to resolve this issue?请让我知道如何解决这个问题?

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!!!')

Simply just use like that只需像那样使用

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

if you want to create the folder before saving如果要在保存之前创建文件夹

os.mkdir('folder_name')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM