类型错误:传递给字节的格式字符串不受支持。\u格式__

2024-09-26 17:56:05 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在尝试将sqlite文件打印为可读格式。我正在使用dionea Honenet的python脚本。每次运行脚本时都会遇到此错误:

File "./readlogsqltree.py", line 268, in print_logins
    login['login_password']))

TypeError: unsupported format string passed to bytes.__format__

login['login_password']是一个取自select语句的变量。下面是正在调用的函数:

def print_logins(cursor, connection, indent):
    r = cursor.execute("""
        SELECT 
            login_username,
            login_password
        FROM 
            logins
        WHERE connection = ?""", (connection, ))
    logins = resolve_result(r)
    for login in logins:
        print("{:s} login - user:'{:s}' password:'{:s}'".format(
            ' ' * indent,
            login['login_username'],
            login['login_password']))

解析结果函数:

def resolve_result(resultcursor):
    names = [resultcursor.description[x][0] for x in range(len(resultcursor.description))]
    resolvedresult = [ dict(zip(names, i)) for i in resultcursor]
    return resolvedresult

光标:

def print_db(opts, args):
    dbpath = 'logsql.sqlite'
    if len(args) >= 1:
        dbpath = args[0]
    print("using database located at {0}".format(dbpath))
    dbh = sqlite3.connect(dbpath)
    cursor = dbh.cursor()

Tags: in脚本formatforsqlitedefargslogin
2条回答

对于Python 3,在调用^{}之前使用^{}解码字符串

我在将某个python2脚本转换为python3时遇到此错误:

  File "/home/dog/Documents/proiecte/tf-booking/tensorflow-object-detection-example/object_detection_app/app.py", line 152, in encode_image
    base64.b64encode(image_buffer.getvalue()))
TypeError: unsupported format string passed to bytes.__format__

解决方案是使用base64.b64encode(image_buffer.getvalue()).decode(),而不是base64.b64encode(image_buffer.getvalue())中的this post

相关问题 更多 >

    热门问题