0

A program I'm trying to convert from python2 to python3 uses PIL the python image library.

I try to download a thumbnail from the web to display within a tkinter style gui. Here is, what I think, the offending line of code:

# grab the thumbnail jpg.
req = requests.get(video.thumb)
photo = ImageTk.PhotoImage(Image.open(StringIO(req.content)))

# now this is in PhotoImage format can be displayed by Tk.
plabel = tk.Label(tf, image=photo)
plabel.image = photo
plabel.grid(row=0, column=2)

The program stops and gives a TypeError, here is the backtrce:

Traceback (most recent call last):   File "/home/kreator/.local/bin/url-launcher.py", line 281, in <module>
    main()
  File "/home/kreator/.local/bin/url-launcher.py", line 251, in main
    runYoutubeDownloader()
  File "/home/kreator/.local/bin/url-launcher.py", line 210, in runYoutubeDownloader
    photo = ImageTk.PhotoImage(Image.open(StringIO(req.content)))
    TypeError: initial_value must be str or None, not bytes

How do I satisfy python3's requirements here?

martineau
  • 119,623
  • 25
  • 170
  • 301
rabbitear
  • 21
  • 2
  • possible duplicate of http://stackoverflow.com/questions/31064981/python3-error-initial-value-must-be-str-or-none – ymonad Sep 16 '16 at 01:25

1 Answers1

2

In this case you can see that the library you have imported doesn't support Python3. This isn't something you can fix from within your own code.

The lack of Python3 support is because PIL has been discontinued for quite some time now. There is a fork that's actively maintained that I would recommend you use instead: https://pillow.readthedocs.io/

You can download it from pypi.

martineau
  • 119,623
  • 25
  • 170
  • 301
shuttle87
  • 15,466
  • 11
  • 77
  • 106