2 qq 37719044 qq_37719044 于 2017.07.17 11:58 提问

python 搜索特殊字符报错问题 50C

如标题,刚开始弄python ,用的数据库是mysqldb webpy框架 搜索& ,{,},%这些字符时不是异常就是500错误

4个回答

playboyanta123
playboyanta123   2017.07.17 12:03

特殊字符存到数据库里面是要经过转义的,不知道你做了没有

oyljerry
oyljerry   Ds   Rxr 2017.07.17 13:42

需要对这些特殊字符进行编码处理。

qq_37719044
qq_37719044 看下我下面的代码 哪里不对么?
10 天之前 回复
qq_37719044
qq_37719044   2017.07.17 13:44

class Show_room:
def GET(self):
data = web.input(currentPage=1,room_name="",order_type="DESC")
room_name = data.room_name
condition_name=""
if (room_name is not None) and (room_name != ""):
condition_name = "and room_name like'%" + room_name + "%'"
print data.currentPage
sql = u'''select * from tbl_classroom where 1=1 {condition_name} order by id DESC '''.format(condition_name=condition_name)
pager = page.Pager(8,int(data.currentPage))
pager.getPager(sql)
return render.classroom(pager,room_name

            贴一下我的代码
qq_37719044
qq_37719044   2017.07.17 13:56

at /classroom_show
Single '}' encountered in format string

Python /usr/local/lib/python2.7/site-packages/MySQLdb/cursors.py in execute, line 186
Web GET http://0.0.0.0:8080/classroom_show
Traceback (innermost first)

/usr/local/lib/python2.7/site-packages/MySQLdb/cursors.py in execute
query = query.format( tuple([db.literal(item) for item in args]))
...
▶ Local vars
/usr/local/lib/python2.7/site-packages/web/db.py in _db_execute
out = cur.execute(query, params) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/web/db.py in query
self._db_execute(db_cursor, sql_query) ...
▶ Local vars
/home/up/桌面/new_project3/project3/ZJMMCC/base_info/page.py in getPager
totalNumber = config.db.query(u'select count(*) cn from (%s) tb'%sql)[0]['cn'] ...
▶ Local vars
/home/up/桌面/new_project3/project3/ZJMMCC/base_info/classroom_base.py in GET
pager.getPager(sql) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/web/application.py in handle_class
return tocall(*args) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/web/application.py in _delegate

搜索 "}"时报错

Csdn user default icon
上传中...
上传图片
插入图片