头条 科技 产经 家电 智能 手机 芯片 数码 电商 WAP版
中国IT产经新闻网-移动互联网与智能搜索领域是未来IT产业发展的趋势!
中国IT产经新闻/产业点评/正文
被服务器拒绝请求常出现415 unsupported media type
来源:
2023-08-17
编辑:晓露

      通常有以下情况:
      1:检查你的http请求头信息,比如因为 User-Agent 被服务器设置拒绝请求了;比如你写的的爬虫,就很有可能因为没有伪装成浏览器,被拒绝请求。
      2:查看你的 http 请求方法,以及服务器端的设置。比如:有一个 强制用 post 请求的接口,你是不是用了非post 请求。
      3:post 请求参数设置,是不是必须的,json 格式。比如下面,两段代码,
      如下 json参数,body


      import requests
      import json
      payload={"userName":"names","userCode":"123456","phoneNum":"7800","regPic":"picData"}
      headers={'content-type': 'application/json'}
      burl="http://httpbin.org/post"
      r=requests.post(burl, data=json.dumps(payload), headers=headers)
      print r.text
      如下 form 格式 参数
      import requests
      import json
      payload={"userName":"names","userCode":"123456","phoneNum":"7800","regPic":"picData"}
      headers={'content-type': 'application/json'}
      burl="http://httpbin.org/post"
      r=requests.post(burl, data=payload, headers=headers)
      print r.text

北汽蓝谷:下跌,亏损、紧抱大腿?

编辑:
2024-05-06
0
8
点评(1)
产业点评更多
厂商动态更多
热门综合更多
CopyRight @ 2008-2023 中国IT产经新闻网 All Right Reserved 违者必究 湘ICP备2022017330号-2