我在使用python读取png
文件时遇到问题,我有一个用于保存数据和读取数据的Web服务器,但是我保存数据的一方在base64中接收图像以将其转换为png文件。 / p>
我创建了图片的路径,例如images/2017-07-23-18-46-30st1folio1.png
的结果。
imgBase64
包含从我的应用程序发送的图像(其他主题)。
path="images/"+str(date_time_path)+str(data['ST_string'])+str(data['Folio_string'])+".png
"
然后我用这个
保存我的数据with open(path, "wb") as fh:
fh.write(imgBase64.decode('base64'))
在这一刻,我可以毫无问题地看到我的照片。
但我的问题是当我尝试用这个
读取这些数据时for ix in photos:
print "Access to path, "+ "./"+str(ix.idSTFolio.path_img)
encoded_string = None
with open("./"+str(ix.idSTFolio.path_img), "rb") as image_file:
encoded_string = b64encode(image_file.read())
print "encoded -> ", encoded_string
在每次迭代中,我都能看到这条路线,当我打印第一行时,我看到了这一点:
./images/2017-07-23-18-46-30st1folio1.png
但最后一行只有打印空字符串,我不知道为什么。如果我的文件存在,并且我尝试编写foo.zip
(它不存在),则返回错误是它不存在,但是当我尝试打印image_file
时,我得到了这个代替:
<open file u'./images/2017-07-23-18-46-30st1folio1.png', mode 'rb' at 0x108123db0>
当我运行我的网络服务器时,我的路径是/Users/MyComputer/Documents/Codes/trackerServer
,我在这条路线中有/images
文件夹,我之前发送了我的图片。有什么想法吗?
截图