Python Forum

Full Version: python classes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(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)
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.
What does this show?

url = "https://api.example.com/rest/addns/{0}".format(line)
print(url)
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
(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).
Pages: 1 2