RIDE转码问题

1、在robotframework中编写脚本,在请求时,参数输入中文会报如下错误,该错误就是编码造成的,通过编写python代码来进行编码转换,然后封装成关键字,再在ride运行;

 ---------报错如下:

20210514 16:25:39.320 : FAIL : InvalidURL: URL can't contain control characters. '/api/deviceInfo/page/info?current=1&size=10&runStatus=&positionStatus=&pole=xb2xe2xcaxd4&groupIdStr=&startTime=&endTime=' (found at least 'xb2')  ,  下图所示

而通过页面调试看到,pole参数值进行转码,所以我们先把中文进行转码,再作为参数 进行请求该url;

 -----------------解决方案--------------

1、先封装成关键字,python脚本如下:

import urllib
def get_bianma(string):
res = urllib.quote(string)
return res

2、导入该.py文件,再调用文件里面 get_bianma 方法进行操作;

原文地址:https://www.cnblogs.com/suhongzhen/p/14769155.html