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/