"ASCII"编解码器无法解码位置 32817 中的字节0xc2:序号不在范围内(128)



我正在尝试从我的学校网站获取课程数据并将其解析为.json文件。我被困在输入代码上:

import urllib.request
with urllib.request.urlopen('https://catalogue.ualberta.ca/') as response:
html = response.read()
decoded = html.decode('ascii')

当我运行这个时,它给了我

'ASCII' codec can't decode byte 0xc2 in position 32817: ordinal not in range(128)

我该如何修复?

,如果没有引起问题的输入,很难对您做得多,但是效果很明显。ASCII是7位代码,序数范围0-127。最大值为0x7f;你超越了。我怀疑您需要的是Unicode,而不是ASCII。请参阅文档。

decoded = html.decode('utf-8')

相关内容

最新更新