0

I need to carry out a GET request for each value that is returned in a variable. My variable is called epics and looks like this:

IN.D.VIX.MONTH2.IP,TM.D.ATHENS.DAILY.IP,KB.D.HEALTH.DAILY.IP,CS.D.EURSEK.TODAY.IP,CF.D.USDNOK.JUN.IP,CF.D.GBPJPY.MAR.IP,IR.D.IB.Month3.IP,IX.D.SUNFUN.DAILY.IP

I basically want to append one epic at a time and perform a get request e.g.

Request 1 
http://api.example.com/v1.14/member?id=IN.D.VIX.MONTH2.IP
Request 2
http://api.example.com/v1.14/member?id=TM.D.ATHENS.DAILY.IP

When I run the code below I get TypeError: range() integer end argument expected, got str.

url = "http://api.example.com/v1.14/epics?id=" + str(epics)
for i in range(epics):
    print(url)
2
  • 2
    for i in range(len(epics)) You need to call the len() function to get the length of the list when using range, this will iterate as many times that len() returns. Commented Jan 17, 2020 at 1:21
  • Thanks but that just appends the entire variable to the URL Commented Jan 17, 2020 at 1:26

1 Answer 1

2

range() takes an integer argument, however your epics variable is presumably some kind of iterable (list?). If you're looking to iterate over each of the values of epics, you can simply reference that in your for loop:

for epic in epics:
    url = "http://api.example.com/v1.14/epics?id=" + str(epic)
    print(url)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.