KnugiHK / WhatsApp-Chat-Exporter

A customizable Android and iOS/iPadOS WhatsApp database parser that will give you the history of your WhatsApp conversations in HTML and JSON. Android Backup Crypt12, Crypt14, Crypt15, and new schema supported.
https://wts.knugi.dev/
MIT License
521 stars 76 forks source link

sqlite3.OperationalError: unable to open database file #12

Open Netherquark opened 2 years ago

Netherquark commented 2 years ago

image

KnugiHK commented 2 years ago

Is your backup encrypted?

Netherquark commented 2 years ago

Nope :/

KnugiHK commented 2 years ago

Are you able to open the Manifest.db with DB Browser for SQLite?

Netherquark commented 2 years ago

Will try

Netherquark commented 2 years ago

Wait the whole backup is sorted into like folders am I supposed to preprocess this somehow?

KnugiHK commented 2 years ago

Folders named from 00 to ff?

Netherquark commented 2 years ago

Yup

KnugiHK commented 2 years ago

You don't have to touch them. There should be a Manifest.db in the root directory of the backup folder.

Netherquark commented 2 years ago

image looks like the db doesnt have a manifest.db

KnugiHK commented 2 years ago

Unless Apple changed the backup structure, the manifest.db should be located in the root directory. You may check if the backup is intact or delete the backup and do it again.

Netherquark commented 2 years ago

I'll redo it and see if I can find the manifest.db

juliuspfadt commented 9 months ago

First of all, thanks for this method. Unfortunately, I encounter a somewhat similar problem, this is from my terminal Screenshot 2023-09-28 at 15 57 20 Do you have any idea what is going on? I have tried opening Manifest.db with DB Browser for sqlite and that seems to work... Cheers

KnugiHK commented 9 months ago

First of all, thanks for this method. Unfortunately, I encounter a somewhat similar problem, this is from my terminal Do you have any idea what is going on? I have tried opening Manifest.db with DB Browser for sqlite and that seems to work... Cheers

Hi. Is your iOS backup encrypted?

juliuspfadt commented 9 months ago

It is not. I specifically chose the option "don't encrypt".

KnugiHK commented 9 months ago

It is not. I specifically chose the option "don't encrypt".

Can you get the value of the final path at line 50 and confirm the path is correct?

    with sqlite3.connect(os.path.join(base_dir, "Manifest.db")) as f:
juliuspfadt commented 9 months ago

Sorry, I don't exactly understand, which path and how would I get it?

KnugiHK commented 9 months ago

Sorry, I don't exactly understand, which path and how would I get it?

Add the following line above line 50.

print(os.path.join(base_dir, "Manifest.db"))

i.e.

def is_encrypted(base_dir):
    print(os.path.join(base_dir, "Manifest.db"))
    with sqlite3.connect(os.path.join(base_dir, "Manifest.db")) as f:
juliuspfadt commented 9 months ago

thanks. I have put the print statement in line 50 of extract_iphone_media.py. I ran the wtsexporter -i -b ~/Library/Application\ Support/MobileSync/Backup/... command again, but get the same output as before, that is, it is not printing.

~/working_wts » wtsexporter -i -b ~/Library/Application\ Support/MobileSync/Backup/...
/Users/julius/Library/Application Support/MobileSync/Backup/.../Manifest.db
Traceback (most recent call last):
  File "/usr/local/bin/wtsexporter", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/Whatsapp_Chat_Exporter/__main__.py", line 271, in main
    extract_iphone_media.extract_media(args.backup)
  File "/usr/local/lib/python3.11/site-packages/Whatsapp_Chat_Exporter/extract_iphone_media.py", line 66, in extract_media
    if is_encrypted(base_dir):
       ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/Whatsapp_Chat_Exporter/extract_iphone_media.py", line 51, in is_encrypted
    with sqlite3.connect(os.path.join(base_dir, "Manifest.db")) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file

the py file lines looks like this:

def is_encrypted(base_dir):
    print(os.path.join(base_dir, "Manifest.db"))
    with sqlite3.connect(os.path.join(base_dir, "Manifest.db")) as f:
        c = f.cursor()
        try:
            c.execute("""SELECT count()
                    FROM Files
                    """)
        except sqlite3.OperationalError as e:
            raise e  # These error cannot be used to determine if the backup is encrypted
        except sqlite3.DatabaseError:
            return True
        else:
            return False
juliuspfadt commented 9 months ago

Ah well, so this was apparently an error on my site. I forgot to add a slash at the end of the device id directory, so it was not properly recognized as base_dir, and you didn't see this error, given I had censored the part of the terminal screenshot. I am sorry for the confusion. For my sake, you may close this issue.

KnugiHK commented 9 months ago

Ah well, so this was apparently an error on my site. I forgot to add a slash at the end of the device id directory, so it was not properly recognized as base_dir, and you didn't see this error, given I had censored the part of the terminal screenshot. I am sorry for the confusion. For my sake, you may close this issue.

So, wtsexporter -i -b ~/Library/Application\ Support/MobileSync/Backup/{device id} does not work while wtsexporter -i -b ~/Library/Application\ Support/MobileSync/Backup/{device id}/ works?

juliuspfadt commented 9 months ago

yes