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发布于 2020-02-07 11:48:03
只需更改斜杠的类型。将其替换为此/。你的代码将变成:
import requests
data = 'C:/Users/abc/Desktop/dashboard/dom.html'
response = requests.get(data)
print (response.json())发布于 2020-02-07 12:26:47
您不能在请求中读取本地文件,默认情况下只能使用http或https协议。但是,您可以编写自定义适配器,但最好的方法是正常读取文件,而不是使用请求。
with open("file.json") as fh:
print(json.load(fh))https://stackoverflow.com/questions/60106791
复制相似问题