'Request' object has no attribute 'META'报错解决
代码如下:
class OrderShipping(LoginRequiredMixin, View):def get(self, request):print("request=",request)shipping_company = request.GET.get("shipping_company")shipping_no = request.GET.get("shipping_no")print("shipping_no=",shipping_no)print("shipping_company=",shipping_company)host = 'https://wuliu.market.alicloudapi.com'path = '/kdi'method = 'GET'appcode = '77652ce3404e414db47d39f58369673e'querys='no='+shipping_no+'&type='+shipping_company# querys = 'no=780098068058&type=zto'#这里需要改掉# no=821383779152&type=SFEXPRESSprint("querys=",querys)bodys = {}url = host + path + '?' + querysrequest = urllib2.Request(url)#这里不能取名叫request,否则会覆盖入口request.add_header('Authorization', 'APPCODE ' + appcode)ctx = ssl.create_default_context()ctx.check_hostname = Falsectx.verify_mode = ssl.CERT_NONEresponse = urllib.request.urlopen(request, context=ctx)content = response.read()print("得到的物流信息是:",content)print(type(content.decode("utf-8")))# return content.decode("utf-8") # if (content):# print(content.decode("utf-8"))return render(request,'shipping_content.html',{'content':json.loads(content.decode("utf-8"))})
解决方案:
class OrderShipping(LoginRequiredMixin, View):def get(self, request):print("request=",request)shipping_company = request.GET.get("shipping_company")shipping_no = request.GET.get("shipping_no")print("shipping_no=",shipping_no)print("shipping_company=",shipping_company)host = 'https://wuliu.market.alicloudapi.com'path = '/kdi'method = 'GET'appcode = '77652ce3404e414db47d39f58369673e'querys='no='+shipping_no+'&type='+shipping_company# querys = 'no=780098068058&type=zto'#这里需要改掉# no=821383779152&type=SFEXPRESSprint("querys=",querys)bodys = {}url = host + path + '?' + querysrequests = urllib2.Request(url)#这里不能取名叫request,否则会覆盖入口requests.add_header('Authorization', 'APPCODE ' + appcode)ctx = ssl.create_default_context()ctx.check_hostname = Falsectx.verify_mode = ssl.CERT_NONEresponse = urllib.request.urlopen(requests, context=ctx)content = response.read()print("得到的物流信息是:",content)print(type(content.decode("utf-8")))# return content.decode("utf-8") # if (content):# print(content.decode("utf-8"))return render(request,'shipping_content.html',{'content':content.decode("utf-8")})
原因是:
阿里云物流的api的Python样例里面的request覆盖了此处类视图中的request。
所以把api里面的request重命名为requests即可。
'Request' object has no attribute 'META'报错解决相关推荐
- AttributeError: ‘Request‘ object has no attribute ‘is_xhr‘ 报错
在用 Flask+VUE 做前后端分离的数据可视化项目时,遇到了这个报错:AttributeError: 'Request' object has no attribute 'is_xhr' 是 We ...
- AttributeError: 'Request' object has no attribute 'is_xhr' 报错的解决办法
在用 Flask+VUE 做前后端分离的数据可视化项目时,遇到了这个报错:AttributeError: 'Request' object has no attribute 'is_xhr' 是 We ...
- AttributeError: 'function' object has no attribute 'Document'报错解决
原因是函数名称和系统中的某个名称相同的,替换另外的名字就行了 报错代码: #读取docx中的文本代码示例 import docx def docx():file=docx.Document(filen ...
- AttributeError: 'NoneType' object has no attribute 'split' 报错处理
报错场景 social_django 组件对原生 django 的支持较好, 但是因为 在此DRF进行的验证为 JWT 方式 和 django 的验证存在区别, 因此需要进行更改自行支持 JWT 方式 ...
- AttributeError: 'NoneType' object has no attribute 'grid'报错解决方案
1问题描述: 当我们在使用tkinter时经常遇到AttributeError: 'NoneType' object has no attribute 'grid'的报错 2.原因分析: import ...
- 'int' object has no attribute 'backward'报错 使用Pytorch编写 Hinge loss函数
在编写SVM中的Hinge loss函数的时候报错"'int' object has no attribute 'backward'" for epoch in range(50) ...
- 【Django】‘function‘ object has no attribute ‘subjects‘报错的解决
项目场景 创建了一个新文件夹 myapp ,用于保存新功能模块下实现功能的代码文件 views.py . 问题描述 运行项目时,报错 'function' object has no attribut ...
- AttributeError: ‘PosixPath‘ object has no attribute ‘rstrip‘ 报错问题记录
环境 python3.6.5 django 3.1.5 问题定位及解决 最近准备开发一个在线教育的网站,各个环境都搭好了,并且测试demo 也能跑的好好的,为了以后 调试接口方便,所以我打算把swag ...
- ‘StandardScaler‘ object has no attribute ‘fit_tranform‘报错原因
原代码: from sklearn.preprocessing import StandardScaler sc = StandardScaler()x_train=sc.fit_tranform(i ...
最新文章
- bzoj1038 [ZJOI2008]瞭望塔
- Memcached原理分析
- [记录] ---阿里云java.io.IOException: Connection reset by peer的问题
- python include_Python如何嵌入C/C++进行开发
- 李晓枫:金融信息化发展和创新的三方面
- 预编译头文件(precompiled header)说明
- 把路由器配置成DHCP服务器,并确保路由功能。
- linux 离线 nfs,Linux 系统 NFS服务
- python爬虫做毕业论文_基于Python的网络爬虫(智联招聘)开发与实现毕业论文+作品源码+演示视频...
- 暴雪守望先锋显示连接暴雪服务器超时,守望先锋 连接暴雪游戏服务器超时
- f检验matlab计算,F检验(F-Test)计算公式与在线计算器_三贝计算网_23bei.com
- matlab教程易,Matlab经典教程—从入门到精通 中文PDF
- Intent直接跳转到Fragment
- python100天从新手到大师下载_GitHub - chenqiyi/Python-100-Days: Python - 100天从新手到大师...
- 【2020】win10java(jdk安装)环境变量配置和相关问题解决
- TTL反相器和CMOS
- termux 安装 kali
- 高仿Telegram IM Chat 聊天软件 即时通讯 在线聊天加社群 纯静态UI架构介绍
- 验证网站代码的免费在线工具
- HDU-4544-湫湫系列故事——消灭兔子--贪心+优先队列
热门文章
- LeetCode 239. Sliding Window Maximum
- URAL 1022 Genealogical tree
- 用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联
- MSF(一):MSF基础
- fusion360安装包_【请注意】2020年以前从Autodesk中国区网站下载的Fusion 360已不能自动升级...
- 如果用户希望将一台计算机,计算机网络试卷(有答案版)
- 春招实习前端面试题汇总
- BOM 浏览器窗口尺寸 浏览器的弹出层 浏览器的地址栏 浏览器的历史记录 浏览器的版本信息 浏览器的常见事件 浏览器卷去的高度和宽度
- css3双击点赞动画,Twitter上的点赞动画
- echarts地图json实现