gpt4 book ai didi

python - “ASCII”编解码器无法解码位置 32817 : ordinal not in range(128) 中的字节 0xc2

转载 作者:行者123 更新时间:2023-11-28 17:07:18 24 4
gpt4 key购买 nike

我正在尝试从学校网站获取类(class)数据并将其解析为 .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。查看documentation .

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

关于python - “ASCII”编解码器无法解码位置 32817 : ordinal not in range(128) 中的字节 0xc2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48671140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com