首页 > 编程语言 > 详细

Python 编写通过post方式提交的接口测试代码

时间:2017-06-19 19:07:28      阅读:387      评论:0      收藏:0      [点我收藏+]

第一次用python编写程序

是照着视频里编写的

但是期间也出现了很多错误

视频内用了是Python2 版本的

而我的是python 3版本的

写这两程序时就发现有很多不同

 

首先

python3没有urllib2这个组件

现在是urllib.request

所以在文件前面引入

import urllib.request

urllib2.Request  更换为  urllib.request.Request

urllib2.urlopen 更换为 urllib.request.urlopen

在编码时一直有报错

POST data should be bytes or an iterable of bytes. It cannot be of type str.

百度后查找到解决方法

编码时在后面加上 .encode(encoding=‘UTF8‘)

 

urllib.parse.urlencode(data).encode(encoding=‘UTF8‘)

 

以上就解决了这个报错

 

Python 编写通过post方式提交的接口测试代码

原文:http://www.cnblogs.com/youding/p/7050009.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!