UnicodeEncodeError: 'charmap' codec can't encode characters

后端 未结 8 755
感情败类
感情败类 2020-11-22 11:55

I\'m trying to scrape a website, but it gives me an error.

I\'m using the following code:

import urllib.request
from bs4 import BeautifulSoup

get =          


        
8条回答
  •  暖寄归人
    2020-11-22 12:27

    set PYTHONIOENCODING=utf-8
    set PYTHONLEGACYWINDOWSSTDIO=utf-8
    

    You may or may not need to set that second environment variable PYTHONLEGACYWINDOWSSTDIO.

    Alternatively, this can be done in code (although it seems that doing it through env vars is recommended):

    sys.stdin.reconfigure(encoding='utf-8')
    sys.stdout.reconfigure(encoding='utf-8')
    

    Additionally: Reproducing this error was a bit of a pain, so leaving this here too in case you need to reproduce it on your machine:

    set PYTHONIOENCODING=windows-1252
    set PYTHONLEGACYWINDOWSSTDIO=windows-1252
    

提交回复
热议问题