1. ホーム

AttributeError: モジュール 'sys' には 'setdefaultencoding' という属性がありません。

2022-02-21 02:23:18
<パス
Python3Exception-AttributeError: module 'sys' has no attribute 'setdefaultencoding

Based on python version 3.6.1, add these 3 lines to a .py file.
import requests, re, sys
reload(sys)
sys.setdefaultencoding("utf-8")
 
 This error occurs.
sys.setdefaultencoding("utf-8")
AttributeError: module 'sys' has no attribute 'setdefaultencoding'
 
Cause Analysis.
Python3 strings are encoded in unicode by default, so sys.setdefaultencoding doesn't exist either
 
Solution.
Remove, sys.setdefaultencoding