gpt4 book ai didi

python - 使用 python 读取 URL 时出错,如何修复

转载 作者:太空宇宙 更新时间:2023-11-03 19:46:27 24 4
gpt4 key购买 nike

import requests
data = 'C:\Users\abc\Desktop\dashboard\dom.html'
response = requests.get(data)
print (response.json())

错误接收为

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

我尝试制作 data = (r'C:\Users\abc\Desktop\dashboard\dom.html') 给出错误

requests.exceptions.InvalidSchema: No connection adapters were found for url

最佳答案

请求中不能读取本地文件,默认只能使用http或https协议(protocol)。但是,您可以编写自定义适配器,但最好的方法是正常读取文件而不是使用请求。

with open("file.json") as fh:
print(json.load(fh))

关于python - 使用 python 读取 URL 时出错,如何修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60106791/

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