首页 > 解决方案 > 谁能告诉下面的代码有什么问题,我收到以下错误:TypeError TypeError:字符串索引必须是整数

问题描述

谁能告诉我下面的代码有什么问题,我收到以下错误: TypeError TypeError: string indices must be integers 特别抱怨这两行:

@main.route('/idm_prototype', methods=['GET', 'POST'])
def search(to_find=None):
if request.method == "POST":
postcodevar = request.form['postcodevar']
print("Assigning SQl statement to a postgreSQL variable")

postgreSQL_select_Query_2 = ("SELECT DISTINCT gss, str(gss), description, 
str(description),  \n"
"postcode str(postcode) FROM postcodelatlng pt, gss.shapes g WHERE st_contains("
"geom,pos) AND  %(postcode)s~*  \n "
" ukpostcode_exact_re()  LIMIT 50"), {'postcode': postcodevar}
LIMIT 50", {'postcode': postcodevar}

for s in range(len(postgreSQL_select_Query_2)):
if postgreSQL_select_Query_2[s]["gss"] == to_find:
cursor.execute("{},{},{}.".format(postgreSQL_select_Query_2[s]["gss"],   
postgreSQL_select_Query_2[s]["description"], postgreSQL_select_Query_2[s] 
["postcode"]))
    
print("Selecting rows from mobile table using cursor.fetchall")
records = cursor.fetchall()
return render_template('idm_prototype.html', data=records)

标签: stringindices

解决方案


推荐阅读