温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python 3.x - Why square brackets in URL is not considered in api testing using robotframework?
api python-3.x robotframework url web-api-testing

python 3.x - 为什么在使用robotframework的api测试中会过滤URL中的方括号?

发布于 2020-03-27 16:08:48

我正在使用Robot框架进行api API测试。当我尝试使用方括号测试api时,没有考虑并得到错误的响应。而相同的api能够在POSTMAN中给出正确的响应。

我有以下API:https : //orbit.com/s2e/api/q1/client/?filter[customField.ID]=1003

当我击中POSTMAN时,我得到的答复是

 "data": { "total_count": "1", "customer": [ { "id": "123" } ] } 

在Robot框架中使用相同的API https://orbit.com/s2e/api/q1/client/?filter[customField.ID]=1003

"data": { "total_count": "0", "customer": [] } 

然后,我看到了各种编码,发现使用%5B和%5D代替了[和],但该API在POSTMAN正常运行,但在robotframework中,它提供了所有数据,即过滤器不起作用。

https://orbit.com/s2e/api/q1/client/?filter%5BcustomField.ID%5D=1003 有人可以在这里引导我吗?

查看更多

提问者
anj
被浏览
210
Sidara KEO 2020-01-31 18:23

通过为Robotframework创建自定义库,应对URL路径进行转码。

对于Python V2

import urllib  def encodeUrlPath(s):  return urllib.quote_plus(s) 

对于Python V3

import urllib.parse def encodeUrlPath(s):  return urllib.parse.quote_plus(s)