解决requests.exceptions.MissingSchema: Invalid URL ‘xxx‘: No schema supplied. Perhaps you meant“xxx”

在使用requests请求接口的时候有时候会爆出个这样的问题,问题的大概意思是无效的url,也就是说这个url是没有效果是错误的,这就就要检查一下url是否符合规定,是否少加了协议

import requests

a=requests.get(url="www.baidu.com")   #缺少协议,这样请求会报错
print(a.json())

b=requests.get(url="http://www.baidu.com")   #加入协议后就能正确访问
print(b.json())

猜你喜欢

转载自blog.csdn.net/m0_58002043/article/details/120987746