weixin_55032679
韩だ霜
2021-06-03 15:29
采纳率: 33.3%
浏览 38

Python 运行request.get报错

Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/untitled/request.py", line 5, in <module>
    requests.post('www.baidu.com')
  File "D:\python\lib\site-packages\requests\api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "D:\python\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\python\lib\site-packages\requests\sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "D:\python\lib\site-packages\requests\sessions.py", line 466, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "D:\python\lib\site-packages\requests\models.py", line 316, in prepare
    self.prepare_url(url, params)
  File "D:\python\lib\site-packages\requests\models.py", line 390, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'www.baidu.com': No schema supplied. Perhaps you meant http://www.baidu.com?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • technologist_24
    CSDN专家-黄老师 2021-06-03 15:45
    已采纳
    import requests
    r = requests.post('https://www.baidu.com/')
    print(r.text)

    你post的url要带http或https,要完整的url地址

    如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢

    点赞 评论
  • weixin_55032679
    韩だ霜 2021-06-03 16:05

    我打印的方式错了,我用Json格式打印的

    点赞 1 评论
  • technologist_09
    CSDN专家-HGJ 2021-06-03 15:45

    检查一下url,是url地址写错了,要写完整,应该在前面加上http:或https:。

    点赞 评论
  • QA_Assistant
    有问必答小助手 2021-06-04 10:50

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    点赞 评论

相关推荐