-1

I am getting proper response from API when I am passing integer value directly but I am not getting any response when I am passing integer through variable. ​

# Extarct information of Metadata of Design id-5071431

import requests

url = "https://www.helioscope.com/api/designs/5071431"

payload={}

headers = {

  'access_token': 'API_key',

}

​

response = requests.request("GET", url, headers=headers, data=payload)

# <Response [200]>

des=5071431

# Extarct information of Metadata of Design id-5071431

import requests

url = "https://www.helioscope.com/api/designs/{des}"

payload={}

headers = {

  'access_token': 'API_key',

}

response = requests.request("GET", url, headers=headers, data=payload)

# <Response [500]>

Attached are the screenshots for the same

enter image description here

enter image description here

Thanks in advance

  • Welcome to stack overflow. We ask that questions include a [mcve] with sample code as _text_ in the body of the question, not as images or links, to make it easier to know how to help. – G. Anderson Feb 25 '22 at 18:59
  • 1
    In your case, you're passing the literal string `'{des}'` as part of your URL. You need to use an f-string or string formatting to use the variable in the string. See [How do I put a variable’s value inside a string?](https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-s-value-inside-a-string) – G. Anderson Feb 25 '22 at 19:00
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Feb 25 '22 at 19:11
  • I want to pass number of design id using for loop. I am not getting response when I am passing integer through variable – Vijay Garg Feb 25 '22 at 19:16
  • There's no loops in this code, but that's also not the problem – OneCricketeer Feb 25 '22 at 19:17
  • Thanks G.Anderson Anderson. It's working now – Vijay Garg Feb 25 '22 at 19:23

1 Answers1

0
  1. response.text will show the server response body

  2. {des} should be replaced with an actual ID like you did in the first request

when I am passing integer through variable.

You're not using an f-string for loading any variables into the string, so it's taken as a literal. You could also just concatenate at the end

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • I want to pass number of design id using for loop. I am not getting respose when I am passing integer through variable – Vijay Garg Feb 25 '22 at 19:15
  • You're getting a Response object in both cases. You'll only get a 200 status code if you use a format string correctly. See https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-s-value-inside-a-string – OneCricketeer Feb 25 '22 at 19:16