Skip to content Skip to sidebar Skip to footer

Task Output Encoding In VSCode

I'm learning BeautifullSoup with Visual Studio Code and when I run this script: import requests from bs4 import BeautifulSoup from fake_useragent import UserAgent ua = UserAgent()

Solution 1:

The problem here seems to be the encoding the python interpreter believes stdout/stderr support. For some reason (arguably, a bug in VSCode) this is set to some platform-specific value (cp1252 in windows for you, I was able to reproduce the issue on OS X and got ascii) instead of utf-8 which the VSCode output window supports. You can modify your task.json to look something like this to address this - it sets an environment variable forcing the Python interpreter to use utf8 for output.

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "python3",
    "isShellCommand": true,
    "args": ["${file}"],
    "showOutput": "always",
    "options": {
        "env": {
            "PYTHONIOENCODING":"utf-8"
        }
    }
}

The relevant bit is the "options" dictionary.


Post a Comment for "Task Output Encoding In VSCode"