'ascii' codec can't encode character : ordinal not in range (128)

后端 未结 2 2030
你的背包
你的背包 2021-01-14 11:10

I\'m scraping some webpages using selenium and beautifulsoup. I\'m iterating through a bunch of links, grabbing info, and then dumping it into a JSON:

for e         


        
2条回答
  •  庸人自扰
    2021-01-14 11:28

    You might need to set PYTHONIOENCODING before running your python script in the shell. For example, I got the same error while redirecting the python script output into a log file:

    $ your_python_script > output.log
    'ascii' codec can't encode characters in position xxxxx-xxxxx: ordinal not in range(128)
    

    After changing PYTHONIOENCODING to UTF8 in the shell, script executed with no ASCII codec error:

    $ export PYTHONIOENCODING=utf8
    
    $ your_python_script > output.log
    

提交回复
热议问题