Reputation: 1
Hi I'm trying to print an sqlite file to a readable format. I'm using dionea honeynet's python script. I encounter this error every time I run the script:
File "./readlogsqltree.py", line 268, in print_logins
login['login_password']))
TypeError: unsupported format string passed to bytes.__format__
The login['login_password'] is a variable taken from a select statement. Here is the function that is being called:
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']))
Resolve result function:
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
Cursor:
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()
Upvotes: 0
Views: 14366
Reputation: 481
I was encountering this error when converting some python2 script to python3:
File "/home/user/Documents/projects/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__
Solution was to use base64.b64encode(image_buffer.getvalue()).decode()
instead of base64.b64encode(image_buffer.getvalue())
as in this post.
Upvotes: 1
Reputation: 1393
For Python 3, decode the string using decode('utf-8')
before calling format()
Upvotes: 0