用python解析url

用python解析url,python,json,parsing,url,Python,Json,Parsing,Url,我想从db info创建一个HTTP链接。例如ip和端口号,不知何故我尝试了这个,但不断得到一个错误无法解析和端口,希望任何人都能帮助我 @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.exec

我想从db info创建一个HTTP链接。例如ip和端口号,不知何故我尝试了这个,但不断得到一个错误无法解析和端口,希望任何人都能帮助我

 @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))
:是一个烧瓶路径,而不是用作URL的内容

如果您想创建这个字符串,它被称为格式化,而不是解析

ipno = doc['ipno']
port = doc['port']
url_uptime = 'https://{}:{}/stats/uptime/'.format(ipno, port)
r_uptime = requests.get(url_uptime, verify=False).content
您还需要在创建文档之前的某个地方定义测试

url='/stats/uptime/' url_正常运行时间='https://'+getVars1+url


非常感谢,伙计

我想你会因为随机字符而出错,然后测试;从来没有定义过。你没有分析任何东西。看起来您正在尝试格式化一个url。谢谢。太好了:如果url已关闭该怎么办?如何说该值为downMove requests。获取对其自身变量的响应,然后查看该变量的状态代码。如果可以,那么获取内容,否则将其设置为down如果我使用状态代码:If url\u uptime.status\u code==requests.codes.ok:r\u uptime=\u session.geturl\u uptime.content其他:r\u uptime=down