0

I need to use my localhost address as the URL. In my endpoint, I have a few different airport codes to get the temperature from a JSON string.

I can type in my browser localhost:5555/temp/lax and the output on that address is just the temperature in Fahrenheit.

I am trying to write a command-line client that will do something like this:

python temp.py sfo

And I will get the output of the temperature at SFO airport.

In the endpoint program, I have my route as:

@app.route('/temp/<airportcode>')

In my mediocre command line client I can get the temperature to print out when I specify exactly what airport I want to see the temp at.

This will work: http://127.0.0.1:5555/temp/lax

But if I try to use this:

t = requests.post("http://127.0.0.1:5555/temp/<airportcode>")

I get a swarm of bad requests.

I also tried requests.get but got the same result.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
dan
  • 21
  • 2
  • Are you asking how to insert a string variable called `airportcode` into a string template? – mkrieger1 Jul 07 '20 at 22:54
  • Try `t = requests.post("http://127.0.0.1:555/temp/{}".format(airportcode))`. See also https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-inside-a-string – mkrieger1 Jul 07 '20 at 22:57

0 Answers0