Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python classes
#11
(Aug-16-2017, 05:07 PM)prsdll6 Wrote: 'https://api.example.com/rest/addns/ + line'
So for every line in the file, regardless of what's in that line, you make a request to literally "https://api.example.com/rest/addns/ + line".  Python doesn't do magic string interpolation (thankfully), you need to identify things that are variables inside strings.

Instead, try this:
http.request("https://api.example.com/rest/addns/{0}".format(line), json.encode #etc)
Reply
#12
I tried this but it gives the same result as using the + symbol.
The problem is when the variable is being passed into the http.request ( ) method the string from the variable 'line' is not getting concatenated the url in the method.
Reply
#13
What does this show?

url = "https://api.example.com/rest/addns/{0}".format(line)
print(url)
Reply
#14
it does show this -
https://api.example.com/rest/addns/testapi1.com

but when the same thing is put into method http.request as udner:
http.request("https://api.example.com/rest/addns/{0}".format(line), 'POST', json.JSONEncoder().encode(array), headers={'Content-type': 'application/json', 'Auth-Token': token})

value in line doesnt get concatenated to the url

When i do this -
http.request(url, 'POST', json.JSONEncoder().encode(array), headers={'Content-type': 'application/json', 'Auth-Token': token})

i get a parse error
Reply
#15
(Aug-17-2017, 07:20 PM)prsdll6 Wrote: but when the same thing is put into method http.request as udner:
http.request("https://api.example.com/rest/addns/{0}".format(line), 'POST', json.JSONEncoder().encode(array), headers={'Content-type': 'application/json', 'Auth-Token': token})
value in line doesnt get concatenated to the url

I don't believe you.  No offense :)


(Aug-17-2017, 07:20 PM)prsdll6 Wrote: When i do this - http.request(url, 'POST', json.JSONEncoder().encode(array), headers={'Content-type': 'application/json', 'Auth-Token': token})
i get a parse error
Please show the whole traceback.  This is starting to sound like there's a different sort of error, maybe on the line above this (like a missing parenthesis).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Classes rob101 4 539 Feb-05-2024, 06:51 PM
Last Post: rob101
  Understanding Python classes PythonNewbee 3 1,194 Nov-10-2022, 11:07 PM
Last Post: deanhystad
Sad Python classes PythonNewbee 4 1,054 Nov-09-2022, 01:19 PM
Last Post: deanhystad
  Inheritance vs Instantiation for Python classes mr_byte31 7 2,882 Oct-14-2021, 12:58 PM
Last Post: mr_byte31
  Understanding Python super() for classes OmegaRed94 1 1,840 Jun-09-2021, 09:02 AM
Last Post: buran
  Python classes Python_User 15 4,886 Aug-04-2020, 06:57 PM
Last Post: Python_User
  Python Classes leodavinci1990 1 2,092 Nov-27-2019, 07:25 AM
Last Post: buran
  Using classes? Can I just use classes to structure code? muteboy 5 5,065 Nov-01-2017, 04:20 PM
Last Post: metulburr
  use of classes in python Lux 2 3,531 Aug-19-2017, 12:29 PM
Last Post: hbknjr

Forum Jump:

User Panel Messages

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