Urllib3 Python3,获得错误未指定主机,但是URL工作正常
我正在尝试从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论