Yesterday I upgraded my “miscellaneous” server out there to Debian bookworm, and that meant (among many other things) that python2 disappeared. I didn’t have many things that depended on python2 on the server, but I was running a copy of http://nirmalpatel.com/fcgi/hn.py there — it’s a script that looks at Hacker News stories, and then attempts to fetch full articles for each story, and then creates an RSS feed from that.
(The RSS feed is then fed to Gwene, of course, so that I can read Hacker News articles in Gnus, as was intended.
(Oh, I forgot to close my parenthesis up there.))
So after working through a few of the normal:
and the usual
and the usual
I finally had everything working, except that I couldn’t print anything out:
That is, I had an object here that seemed to be both a byte string and a string string at the same time! Schroedinger’s String!
So I tried reproducing, and:
Oh, I couldn’t write anything out?
streamWriter = codecs.lookup('utf-8')[-1] sys.stdout = streamWriter(sys.stdout)
Because the script had the above in the start — I guess that was the way you told Python to encode to UTF-8 in the olden days?
I dunno — I don’t know Python… but now the script works! Under Python3! I used the age-old technique of adding .encode('utf-8') into the code at random, and I’ve put the results on Microsoft Github. I didn’t write it, so I take none of the blame! Except for the Python3 parts.