qq_37719044
变速蛇皮
采纳率0%
2017-07-17 03:58 阅读 1.7k

python 搜索特殊字符报错问题

50

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • playboyanta123 show_code 2017-07-17 04:03

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

    点赞 评论 复制链接分享
  • oyljerry oyljerry 2017-07-17 05:42

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

    点赞 评论 复制链接分享
  • qq_37719044 变速蛇皮 2017-07-17 05: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 变速蛇皮 2017-07-17 05: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

    搜索 "}"时报错

    点赞 评论 复制链接分享

相关推荐