Encoding problems on windows cmd (python3)

My app is having some problems to display certain characters in windows cmd. For now, it doesn’t have an UI. I made it on Linux Mint 18 and it works fine there. Here are images:

How it’s supposed to show:
TSM Kripp Elder Scrolls: Legends Ranked Day! Giveaway At Midnight EDT! http://goo.gl/svjoeF #sponsored (✿:yin_yang:‿:yin_yang:✿)(✿:yin_yang:‿:yin_yang:✿)

This is on windows:

This is after adding .encode(‘utf-8’) to that line, otherwise it crashes. Anyone can help me parse this correctly? Code follows:

def live(self): """Displays online followed channels""" games = [] streams = [] fl = requests.get("https://api.twitch.tv/kraken/streams/followed?oauth_token="+self.oauth_rnd) for i in range(len(fl.json()['streams'])): if fl.json()['streams'][i]['game'] not in games: games.append(fl.json()['streams'][i]['game']) streams.append((fl.json()['streams'][i]['channel']['name'], fl.json()['streams'][i]['channel']['status'].encode('utf-8'), fl.json()['streams'][i]['game'])) games.sort() print("\n{0:*^60}".format("")) print("{0:*^60}".format("LIST OF ONLINE STREAMS")) print("{0:*^60}".format("")) for i in range(len(games)): print(u"\n{0}{1}".format("*"*10, games[i])) for c in range(len(streams)): if streams[c][2] == games[i]: print(streams[c][0], ":", streams[c][1])

Make sure that your console window font supports utf8, by default i don’t think it does.

1 Like

It seems like cmd has a lot of problems with compatibility. I’ll leave it be for now. Thank you!

start the whole thing with a “chcp 65001”

That will set you to UTF-8 in a command prompt.

EDIT: Just did a quick google to see if there was a way to lock it in, and found this: http://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8

I think it might help.

1 Like

I think I can incorporate this. Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.