1

I've just installed Flask and it's my first time using it. After following the demo on the site, I managed to set up the webserver, but for some reason, it outputs unreadable characters

D:\Dafuq\SELF\Flask\Blog>python app.py
Unicode characters: љњертѕуиопасдфгхјклчќзџцвбнм
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
Unicode characters: љњертѕуиопасдфгхјклчќзџцвбнм
 * Debugger is active!
 * Debugger PIN: 782-294-512
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Feb/2019 09:52:35] "[37mGET / HTTP/1.1[0m" 200 -
127.0.0.1 - - [16/Feb/2019 09:52:36] "[33mGET /favicon.ico HTTP/1.1[0m" 404 -

I outputed some unicode characters, and the console prints them with no issue. What could be the problem for the unrecognized characters at the GET request lines?

Thank you

zafirzarya
  • 143
  • 1
  • 10
  • unreadable? which ones? Oh the [33m stuff I suppose. Those are ANSI escape code for colors in console. If the console doesn't understand them or output is redirected, they are displayed as is, and it's ugly – Jean-François Fabre Feb 16 '19 at 09:03
  • maybe this can help, or is a duplicate https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python – Jean-François Fabre Feb 16 '19 at 09:05

3 Answers3

1

Do you use a "termcolor" package or something that deals with colors in the terminal? I just deleted it and the problem disappeared.

1

I know this is old, but I had the same issue and wanted to share. This seems to be a problem with Windows, as stated in this issue.

The following fixed it:

import os
import sys

if sys.platform.lower() == "win32": 
    os.system('color')
Pyxels
  • 11
  • 1
  • 2
0

The following solution taken from this SuperUser post worked for me to remove the ANSI characters:

The registry key at HKEY_CURRENT_USER\Console\VirtualTerminalLevel sets the global default behavior for processing ANSI escape sequences. Create a DWORD key (if necessary) and set its value to 1 to globally enable (or 0 to disable`) ANSI processing by default.

[HKEY_CURRENT_USER\Console]
"VirtualTerminalLevel"=dword:00000001
Ayşe Nur
  • 493
  • 7
  • 11