在我的代码中,我不断收到此错误...
UnicodeEncodeError: 'charmap' codec can't encode character '\u2013' in position 390: character maps to <undefined>
我试图放置一个除了 UnicodeError 和 UnicodeEncodeError 但没有任何作用,问题是它是用户输入,所以我无法控制他们输入的内容,所以我需要所有编码错误来显示一个显示错误而不是崩溃程序的打印.. .
try:
argslistcheck = argslist[0]
if argslistcheck[0:7] != "http://":
argslist[0] = "http://" + argslist[0]
with urllib.request.urlopen(argslist[0]) as url:
source = url.read()
source = str(source, "utf8")
except urllib.error.URLError:
print("Couln't connect")
source = ""
except UnicodeEncodeError:
print("There was an error encrypting...")
source = ""
追溯:
Traceback (most recent call last):
..... things leading up to error
File "C:\path", line 99, in grab print(source)
File "C:\Python33\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2013' in position 390: character maps to <undefined>