在Heroku上,无法将 Dataframe 保存为imgafe并发送给用户

ulydmbyx  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(178)

我的电报机器人代码有行(尝试了所有三个)。此代码在本地计算机上正常工作,但当上传到Heroku时,无法使其创建 Dataframe 的图像并发送给用户。无法理解为什么会发生这种情况。

import dataframe_image as dfi
dfi.export(ddf2, "table.png") 
dfi.export(ddf2, str(user)+".png")
dfi.export(ddf2, str(user)+".png",table_conversion='chrome')


2022-07-29T06:03:20.632128+00:00 app[worker.1]:   File "/app/t_bot.py", line 191, in out
2022-07-29T06:03:20.632266+00:00 app[worker.1]:     dfi.export(ddf2, str(user)+".png",table_conversion='chrome', chrome_path='/app/.chromedriver/bin/chromedriver')
2022-07-29T06:03:20.632279+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/dataframe_image/_pandas_accessor.py", line 24, in export
2022-07-29T06:03:20.632375+00:00 app[worker.1]:     return _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path)
2022-07-29T06:03:20.632383+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/dataframe_image/_pandas_accessor.py", line 73, in _export
2022-07-29T06:03:20.632462+00:00 app[worker.1]:     img_str = converter(html)
2022-07-29T06:03:20.632471+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/dataframe_image/_screenshot.py", line 167, in run
2022-07-29T06:03:20.632585+00:00 app[worker.1]:     img = self.take_screenshot()
2022-07-29T06:03:20.632586+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/dataframe_image/_screenshot.py", line 119, in take_screenshot
2022-07-29T06:03:20.632679+00:00 app[worker.1]:     img = mimage.imread(buffer)
2022-07-29T06:03:20.632683+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/matplotlib/image.py", line 1560, in imread
2022-07-29T06:03:20.633021+00:00 app[worker.1]:     with img_open(fname) as image:
2022-07-29T06:03:20.633021+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/PIL/ImageFile.py", line 116, in __init__
2022-07-29T06:03:20.633127+00:00 app[worker.1]:     self._open()
2022-07-29T06:03:20.633145+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/PIL/PngImagePlugin.py", line 712, in _open
2022-07-29T06:03:20.633388+00:00 app[worker.1]:     raise SyntaxError("not a PNG file")
2022-07-29T06:03:20.633425+00:00 app[worker.1]: SyntaxError: not a PNG file

我将添加PyCharm脚本,以显示DataFrame在本地设备上正常工作和导出。

k7fdbhmy

k7fdbhmy1#

正如您在评论中提到的,这就是解决方案

table_conversion='matplotlib'

所以在你的情况下

import dataframe_image as dfi
dfi.export(ddf2, "table.png") 
dfi.export(ddf2, str(user)+".png")
dfi.export(ddf2, str(user)+".png",table_conversion='matplotlib')

相关问题