将输入从变量传递到URL路径参数-Python

问题描述 投票:1回答:1

请让我知道如何从变量将输入发送到URL路径参数。我确实有关于通过有效负载将输入传递到Query Parameter的想法,但是在API以下使用路径参数,我需要将83+作为变量传递,我不知道我如何通过它们:

http://localhost:8184/messenger/webapi/Calculator/8/3/+
python python-requests pytest web-api-testing
1个回答
3
投票

您可以只使用字符串插值来构建URL。在将值放入URL之前,请确保引用值:

from urllib import quote

op1, op2, operator = '8', '3', '+'
url = 'http://localhost:8184/messenger/webapi/Calculator/{}/{}/{}'.format(
    quote(op1), quote(op2), quote(operator))
© www.soinside.com 2019 - 2024. All rights reserved.