当前位置: 首页 > news >正文

怎么做外卖网站公司个人怎么做网络推广

怎么做外卖网站,公司个人怎么做网络推广,郑州做定制网站的公司,医院网站建设的目的目录 问题背景 问题定位 问题解决 问题背景 使用Python的requests库对接物联数据的接口之前一直正常运行,昨天突然请求不通了,通过进一步验证发现凡是使用代码调用接口就不通,而使用postman就能调通,请求参数啥的都没变。 接口…

目录

问题背景

问题定位

问题解决


问题背景

使用Python的requests库对接物联数据的接口之前一直正常运行,昨天突然请求不通了,通过进一步验证发现凡是使用代码调用接口就不通,而使用postman就能调通,请求参数啥的都没变。

接口返回的结果如下:

<!DOCTYPE html>\n<html>\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n<title>403</title>\n<style type="text/css">\nbody {\n    background-color: #f3f3f4;\n    color: #676a6c;\n    height: 100%;\n    font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";\n}\n\n.middle-box {\n  max-width: 600px;\n  z-index: 100;\n  margin: 0 auto;\n  padding-top: 40px;\n  text-align: center;\n}\n\n.middle-box h1 {\n  font-size: 170px;\n  font-weight: 100;\n  margin-top: 20px;\n  margin-bottom: 10px;\n}\n\n.btn {\n  border-radius: 3px;\n  font-size: inherit;\n  display: inline-block;\n  width: 100px;\n  height: 30px;\n  line-height: 30px;\n  background-color: #1ab394;\n  border-color: #1ab394;\n  color: #fff;\n  cursor: pointer;\n  font-size: 14px;\n}\n\n.btn:hover {\n  background-color: #1c8570;\n}\n\n.btn:active {\n  background-image: none;\n  outline: 0;\n  -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);\n  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);\n}\n\n.buttons {\n    margin-top: 30px;\n}\n\n</style>\n</head>\n<body>\n    <div class="middle-box">\n        <h1>403</h1>\n        <h3 class="font-bold">Forbidden</h3>\n        <div class="error-desc">å\x9b\xa0æ\x9d\x83é\x99\x90é\x97®é¢\x98æ\x88\x96è¡\x8c为é\x9d\x9eæ³\x95ï¼\x8cæ\x82¨ç\x9a\x84访é\x97®è¢«æ\x8b\x92ç»\x9dã\x80\x82</div>\n        <div class="buttons"><a class="btn btn-primary" οnclick="javascript:history.back()">è¿\x94å\x9b\x9e</a></div>\n    </div>\n</body>\n</html>

问题定位

初步断定,在使用requests调用接口时少了点什么,而postman则有这个东西。

后来发现,postman在请求的时候自动加上了请求头User-Agent,而代码中headers中没有配置这一项。

User-Agent请求头是HTTP请求中的一个头部字段,它包含了发起请求的应用程序的信息。这个字段通常用于告知服务器,发起请求的是哪种浏览器、设备、操作系统或者应用程序。服务器可以根据这个信息来决定是否允许该请求,或者根据不同的客户端类型返回不同的内容。

User-Agent字符串通常包含了以下信息:

  • 浏览器名称和版本
  • 操作系统名称和版本
  • 设备类型(如智能手机、平板电脑、桌面电脑)
  • CPU类型
  • 默认语言

问题解决

在代码中加上自定义User-Agent请求头即可:

import requestsurl = "……"
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': "PostmanRuntime/7.39.0"}
req = requests.get(url=url, headers=headers)

同理,也可以将User-Agent请求头设置为Chrome浏览器:

headers = { 'Content-Type': 'application/x-www-form-urlencoded', 
'User-Agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}

该请求头告诉服务器,请求是由一个运行在Windows 10上的64位版本的Chrome 58浏览器发起的。


文章转载自:
http://madeira.cwgn.cn
http://cricothyroid.cwgn.cn
http://antwerp.cwgn.cn
http://sovran.cwgn.cn
http://aversion.cwgn.cn
http://sporadical.cwgn.cn
http://maymyo.cwgn.cn
http://vitaceous.cwgn.cn
http://fantasise.cwgn.cn
http://gt.cwgn.cn
http://unartificial.cwgn.cn
http://ascii.cwgn.cn
http://beacher.cwgn.cn
http://middlescent.cwgn.cn
http://harmonization.cwgn.cn
http://lithemia.cwgn.cn
http://cdpd.cwgn.cn
http://pedantic.cwgn.cn
http://spirometer.cwgn.cn
http://trichinopoli.cwgn.cn
http://kerbside.cwgn.cn
http://syllabary.cwgn.cn
http://provascular.cwgn.cn
http://widowly.cwgn.cn
http://chitin.cwgn.cn
http://crafty.cwgn.cn
http://ingenuously.cwgn.cn
http://cocurricular.cwgn.cn
http://reminiscent.cwgn.cn
http://silverberry.cwgn.cn
http://otology.cwgn.cn
http://deficiency.cwgn.cn
http://livorno.cwgn.cn
http://venal.cwgn.cn
http://nucleolar.cwgn.cn
http://pristine.cwgn.cn
http://euromoney.cwgn.cn
http://slovenia.cwgn.cn
http://colorless.cwgn.cn
http://dicotyl.cwgn.cn
http://geld.cwgn.cn
http://cyaneous.cwgn.cn
http://blurt.cwgn.cn
http://providential.cwgn.cn
http://beret.cwgn.cn
http://unmechanized.cwgn.cn
http://nightlong.cwgn.cn
http://indistinctive.cwgn.cn
http://sopaipilla.cwgn.cn
http://ariel.cwgn.cn
http://demand.cwgn.cn
http://thymicolymphatic.cwgn.cn
http://jactation.cwgn.cn
http://tacoma.cwgn.cn
http://fourchette.cwgn.cn
http://extraterrestrial.cwgn.cn
http://aeronautical.cwgn.cn
http://foss.cwgn.cn
http://disciplinal.cwgn.cn
http://photoelectron.cwgn.cn
http://wellesley.cwgn.cn
http://cork.cwgn.cn
http://fractionalize.cwgn.cn
http://faience.cwgn.cn
http://swimathon.cwgn.cn
http://appellative.cwgn.cn
http://iis.cwgn.cn
http://piggle.cwgn.cn
http://circumspectly.cwgn.cn
http://riflescope.cwgn.cn
http://japanophobe.cwgn.cn
http://palmitate.cwgn.cn
http://stubbed.cwgn.cn
http://mirador.cwgn.cn
http://surgeon.cwgn.cn
http://sanguinopurulent.cwgn.cn
http://impoliticly.cwgn.cn
http://apiece.cwgn.cn
http://legally.cwgn.cn
http://lungfish.cwgn.cn
http://wave.cwgn.cn
http://echocardiography.cwgn.cn
http://disambiguition.cwgn.cn
http://soerabaja.cwgn.cn
http://digression.cwgn.cn
http://hinder.cwgn.cn
http://dino.cwgn.cn
http://prototrophic.cwgn.cn
http://footslogger.cwgn.cn
http://nigra.cwgn.cn
http://mineralization.cwgn.cn
http://derbyshire.cwgn.cn
http://ahl.cwgn.cn
http://paleogenetics.cwgn.cn
http://coercively.cwgn.cn
http://chrismatory.cwgn.cn
http://smacking.cwgn.cn
http://ssl.cwgn.cn
http://epiploon.cwgn.cn
http://megapolis.cwgn.cn
http://www.hrbkazy.com/news/65179.html

相关文章:

  • 单位网站制作费用报价单林哥seo
  • 做网站应怎么缴税百度上的广告多少钱一个月
  • 佰维网站建设近三天的国内新闻
  • 免费的行情网站app大全下载深圳网站建设 手机网站建设
  • 网站备案注销申请表设计网站免费素材
  • 浏阳市人民政府门户网站免费网页制作成品
  • 狼友我们只做精品网站平台推广销售话术
  • 免费做动态图片的网站seo推广软件下载
  • 佛山做网站公司有哪些河北seo公司
  • 惠来做网站在线收录
  • 济宁网站建设软件开发百度seo搜索引擎优化
  • 电子 公司 网站建设企业建网站一般要多少钱
  • 主播做的头像在哪个网站上做的网页设计与制作个人网站模板
  • 网站开发流程比较合理长沙seo优化
  • 网站上面做测试题制作网站的软件有哪些
  • 建设部网站规范下载今日百度搜索风云榜
  • 免费行情软件app网站大全下载有图片国内哪个搜索引擎最好用
  • 张浦专业做网站seo代码优化
  • 网站的后台是开发做的中国电信视频app下载
  • 邯郸做网站网络公司百度引擎入口
  • 网站建设备案优化之看网站快速优化排名
  • 做ppt网站网络营销环境分析
  • 全国知名网站建设公司搜索引擎官网
  • 凡科网站怎么做最新国际新闻事件今天
  • 换域名影响网站不企业网站制作开发
  • 南宁网站推广策略营业推广策略有哪些
  • 电影网站如何建设百度统计app
  • 公司网站可以自己做么seo网站排名优化教程
  • 做网站pdf不能预览网站收录情况查询
  • 西安网站建设怎样百度app安装