chivas_hvn
chivas_hvn

Reputation: 371

Passing input to URL path parameter from variable - Python

Please someone let me know how I could send input to URL path parameter from a variable. I do have an idea on passing input to Query Parameter through payload but below API uses path parameter and I need to pass 8, 3 and + as variables and I do not have an idea how I could pass them:

http://localhost:8184/messenger/webapi/Calculator/8/3/+

Upvotes: 1

Views: 6636

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124248

You could just use string interpolation to build a URL. Do make sure you quote your values before putting them in the URL:

from urllib import quote

op1, op2, operator = '8', '3', '+'
url = 'http://localhost:8184/messenger/webapi/Calculator/{}/{}/{}'.format(
    quote(op1), quote(op2), quote(operator))

Upvotes: 3

Related Questions