-1

My telegram bot code has line (tried all three). This code works normally on local computer but when upload to Heroku, can't make it to create image of dataframe and send to user. Can't understand why it happens.

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

I'm adding PyCharm script to show that DataFrame works normally and exports normally on local device. enter image description here

Zaur
  • 23
  • 7
  • What value does `ddf2` have? Where does it come from? Are you 100% sure it's valid PNG data? If you answer yes to that last question, please also convince _us_. What makes you so confident that it's valid? – ChrisGPT was on strike Jul 29 '22 at 12:33
  • @Chris. As I mentioned ddf2 is data frame. Telebot uses dataframe_image to send it's png version. All works on local computer (PyCharm, and telegram works normally) But when it comes to heroku it returns this error. First it was telling that I don't have chrome driver. Then I used buildpacks for it. But now I have problems with creating png of DataFrame, while locally it works. – Zaur Jul 29 '22 at 14:45
  • I know it's a dataframe. But does it contain _valid data?_ How does it get created? – ChrisGPT was on strike Jul 29 '22 at 20:18
  • @Chris Considering that I've mentioned several times that It works in PyCharm it could be understood that data is valid. I don't know why should I convince anyone?! if anyone doesn't know how to help he/she can just mark qustion with negative point, like the question is guilty. I added PyCharm print screen. I wrote that it has something to do with Heroku Chrome driver. Please if you don't know the solution don't spend your time trying to be convinced, just complaint about my question and grade it with "-1". – Zaur Jul 29 '22 at 21:44
  • The data in memory when you run locally has no bearing on the data in memory on Heroku. I am asking you to confirm whether you have valid data _on Heroku_. When you get an error that effectively tells you your data isn't valid, checking to make sure you have valid data is a pretty reasonable first step. I'm not sure why you think this related to the ChromeDriver—you don't mention that anywhere in your question and your previous comment just says you didn't have it properly installed and now you do. Please read [ask]. – ChrisGPT was on strike Jul 31 '22 at 14:07
  • @Chris data on Heroku is valid. App started working when I changed table_conversion='matplotlib' on Heroku. As I understand even it says that problem is with file type problem is with Chrome. I installed Chrome via builpack on Heroku. Still can't understand why it doesn't accept chrome on Heroku and how to solve it – Zaur Jul 31 '22 at 14:31

1 Answers1

0

As you have mentioned in the comments this is the solution

table_conversion='matplotlib'

So in your case that's

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')