如何使用 httplib2 上传图像,但不将其保存到我的计算机?

How can I use httplib2 to upload an image, but not save it to my computer?

如何使用 httplib2 从站点接收图像,但不将其保存到我的计算机,但同时我可以使用它。我的代码是:

h = httplib2.Http('.cache')
response, content = h.request(self.url + 'v1588505946/images/mc-donalds_vexbhd.png')
out = open('images2/' + self.names[1], 'wb')
out.write(content) # How to avoid this line
out.close()
self.img1 = Image.open('images2/' + self.names[1]) # Here I want to open the image directly from the server
self.img1 = ImageTk.PhotoImage(self.img1)

直接用BytesIO转换,就可以用Image.open直接打开了。 示例:

from io import BytesIO

...

response, content = h.request(self.url + 'v1588505946/images/mc-donalds_vexbhd.png')
self.img1 = Image.open(BytesIO(content))