Converting python2 PIL to python3 code
<p>A program I'm trying to convert from python2 to python3 uses <code>PIL</code> the python image library.</p>

<p>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:</p>

<pre><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)
</code></pre>

<p>The program stops and gives a TypeError, here is the backtrce:</p>

<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):   File "/home/kreator/.local/bin/url-launcher.py", line 281, in &lt;module&gt;
    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
</code></pre>

<p>How do I satisfy python3's requirements here?</p>

<p>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.</p>

<p>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: <a href="https://pillow.readthedocs.io/" rel="nofollow">https://pillow.readthedocs.io/</a></p>

<p>You can download it from <a href="https://pypi.python.org/pypi/Pillow" rel="nofollow">pypi</a>.</p>

python python-3.5