Urllib3 Python3,获得错误未指定主机,但是URL工作正常

发布于 2025-01-20 14:09:13 字数 714 浏览 2 评论 0原文

我正在尝试从Excel表将图像写入数据库。我有此功能可以下载图像。

def downloadImage(url, Name):
    try:
        http    = urllib3.PoolManager()
        image   = http.request("GET", url, preload_content=False).data

    with File(open(f'{Name}-{timezone.now()}.jpg', 'wb')) as handler:
        handler.write(image)
    with handler.open(mode='rb') as nana:
        pass
except Exception as e:
    raise ValueError(e)
return handler

这是网址之一:

https://i.imgur.com/bwommav.jpg,当我打印URL时,我已经看到了帖子,我看到了http/https的帖子,但是这里的URL工作正常。

谁能告诉我问题在哪里?

这就是函数的方式

Image(obj=instances[i], images=downloadImage(user['image1'], user['name']).open(mode='rb'))

感谢

I am trying to write images to database from excel sheet. I have this function to download images.

def downloadImage(url, Name):
    try:
        http    = urllib3.PoolManager()
        image   = http.request("GET", url, preload_content=False).data

    with File(open(f'{Name}-{timezone.now()}.jpg', 'wb')) as handler:
        handler.write(image)
    with handler.open(mode='rb') as nana:
        pass
except Exception as e:
    raise ValueError(e)
return handler

This is one of the url:

https://i.imgur.com/BWomMaV.jpg, When I print the url, it is similar coz I have seen posts where http/https is not added, but here the url works fine.

Can anyone tell me where the issue is?

This is how the function is called

Image(obj=instances[i], images=downloadImage(user['image1'], user['name']).open(mode='rb'))

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文