0

I want to create a HTTP link from db info. such as ip and port number, somehow i tried this but keep getting a error cant parse and port hope any one can help me out

 @app.route('/link_test/<string:id>')
 @is_logged_in
 def link_test(id):
     #Create cursor
     cur = mysql.get_db().cursor()
     #get item by itemno
     result = cur.execute("SELECT * FROM testlist WHERE id = %s", [id])
     doc = cur.fetchone()

        )
     doc = {"id": test[0], "rdno": test[1], "ipno": test[2], "port": test[3]}
     cur.close()
     ipno = test['ipno']
     port = test['port']
     url_uptime = 'https://<string:ipno>:<string:port>/stats/uptime/'  

     return render_template('link_test.html', uptime=json.loads(r_uptime))
1
  • I think you're getting an error because of the random ) character, and test;is never defined. And you're not parsing anything. Looks like you're trying to format a URL Commented Sep 23, 2018 at 14:37

2 Answers 2

1

<string:ipno>:<string:port> is a Flask path, not something to be literally used as a URL

If you wanted to create this string, it's called formatting, not parsing

ipno = doc['ipno']
port = doc['port']
url_uptime = 'https://{}:{}/stats/uptime/'.format(ipno, port)
r_uptime = requests.get(url_uptime, verify=False).content

You'll also want to define test somewhere before doc is created

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks mate great :)
what if the url is down how to say the value is "down"
Move requests.get response to its own variable, then check out the status code of that. If it's okay, then get the content, else set it to "down"
What if i use status_code: if url_uptime.status_code == requests.codes.ok: r_uptime = _session.get(url_uptime).content else: r_uptime = "down"
0

getVars1 = doc[2]

url='/stats/uptime/' url_uptime = ('https://'+getVars1+url)

great thanks mate

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.