Python Forum
need help in passing url as variable in payload
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help in passing url as variable in payload
#1
Hello Team,

I need help in code to post variable( which has url) in the body of post api call. Here is code.

stashurl = 'https://<someurl>_{}/{}'.format(quote(app), quote(querystring))
payload = "{\"inputParameters\": [{\"name\": \"url\",\"value\": \"stashurl\"t}]}"

How to pass the stashurl variable in payload to post it to another api.
Reply
#2
http://www.pythonforbeginners.com/concat...-in-python
https://softwareengineering.stackexchang...le_rich_qa
You need to concatenate the parts into one string.
Reply
#3
Thanks for the reply, I was able to concatenate the string, but how to use that string variable in body of rest api
Reply
#4
I don't understand exactly what you are doing, so I cannot help you.
This is all I could think of:
https://stackoverflow.com/questions/4542...le_rich_qa
Reply
#5
(Apr-20-2018, 01:42 AM)vkvasu25 Wrote: Thanks for the reply, I was able to concatenate the string, but how to use that string variable in body of rest api
You use Requests and send it as post with payload,based on what API accept.
Example here i use httpbin which can do test against.
>>> import requests
>>> 
>>> headers = {'Content-type': 'application/json'}
>>> payload = {"device_name": 'Super-Pc', 'DevicePort': 666}
>>> r = requests.post('http://httpbin.org/post', headers=headers, json=payload)
>>> r.status_code
200
>>> r.json()
{'args': {},
 'data': '{"device_name": "Super-Pc", "DevicePort": 666}',
 'files': {},
 'form': {},
 'headers': {'Accept': '*/*',
             'Accept-Encoding': 'gzip, deflate',
             'Connection': 'close',
             'Content-Length': '46',
             'Content-Type': 'application/json',
             'Host': 'httpbin.org',
             'User-Agent': 'python-requests/2.18.4'},
 'json': {'DevicePort': 666, 'device_name': 'Super-Pc'},
 'origin': '85.165.158.220',
 'url': 'http://httpbin.org/post'}
>>> r.json()['json'][ 'device_name']
'Super-Pc'
Reply
#6
I want to pass url as input to body of post Ali call

I want to pass url as input to body of post Api call as shown in my code , I Want to pass that data to rest api

To define simply, I Wanto pass exactly same data as shown in payload,
payload = "{\"inputParameters\": [{\"name\": \"url\",\"value\": \"someurl\"t}]}"
But it is throwing error as <link
Reply
#7
To define simply, I Wanto pass exactly same data as shown in payload,
payload = "{\"inputParameters\": [{\"name\": \"url\",\"value\": \"someurl\"t}]}"
But it is throwing error as <link

Also the url in the payload has multiple endpoints
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  passing php variable to python file jerald 1 2,679 Jul-07-2021, 11:46 AM
Last Post: Larz60+
  passing variable to function Rejoice 4 2,869 Sep-11-2020, 03:27 AM
Last Post: Pleiades
  Passing variable to another function JonnyDriller 10 3,776 Feb-05-2020, 03:46 AM
Last Post: JonnyDriller
  Invalid JSON payload received. Unknown name “”: Root element must be a message." hellraiser 4 13,244 Aug-18-2019, 03:41 PM
Last Post: hellraiser
  Passing a local variable outside of a function malonn 8 3,928 Apr-15-2019, 01:50 AM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020