libkeepass / pykeepass

Python library to interact with keepass databases (supports KDBX3 and KDBX4)
https://pypi.org/project/pykeepass/
GNU General Public License v3.0
403 stars 96 forks source link

PyKeePass changes backslashes in raw string when parsed #394

Closed charlesvarthur closed 3 weeks ago

charlesvarthur commented 1 month ago

I'm trying to reach a Keepass file, held on a network drive, however the Keepass module looks to have problems in handling the backslashes. I've tried a number of options including regex, replace, raw strings and os.path.join methods, to try and find a way to enable pykeepass to accept the string, but the output always changes.

The code:

key_loc = r'\\my-org\some-directory\KeePass\servers.kdbx'
print(key_loc)

kp = PyKeePass(key_loc, password='testing123')
dev_svr = kp.find_groups(name='my_server', first=True)
entry = kp.find_entries(title='my_user', first=True)

The output

\\my-org\some-directory\KeePass\servers.kdbx

Traceback (most recent call last):
  File "kp-test.py", line 6, in <module>
    kp = PyKeePass(key_loc, password='testing123')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pykeepass.py", line 63, in __init__
    self.read(
  File pykeepass.py", line 103, in read   
    self.kdbx = KDBX.parse_file(
                ^^^^^^^^^^^^^^^^
  File "core.py", line 424, in parse_file  
    with open(filename, 'rb') as f:
         ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '\\\\my-org\\some-directory\\KeePass\\servers.kdbx'
Evidlo commented 1 month ago

https://stackoverflow.com/questions/7169845/using-python-how-can-i-access-a-shared-folder-on-windows-network

On June 11, 2024 7:11:25 AM CDT, Charles Arthur @.***> wrote:

I'm trying to reach a Keepass file, held on a network drive, however the Keepass module looks to have problems in handling the backslashes. I've tried a number of options including regex, replace, raw strings and os.path.join methods, to try and find a way to enable pykeepass to accept the string, but the output always changes.

The code:

key_loc = r'\\my-org\some-directory\KeePass\servers.kdbx'
print(key_loc)

kp = PyKeePass(key_loc, password='testing123')
dev_svr = kp.find_groups(name='my_server', first=True)
entry = kp.find_entries(title='my_user', first=True)

The output

\\my-org\some-directory\KeePass\servers.kdbx

Traceback (most recent call last):
 File "kp-test.py", line 6, in <module>
   kp = PyKeePass(key_loc, password='testing123')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "pykeepass.py", line 63, in __init__
   self.read(
 File pykeepass.py", line 103, in read   
   self.kdbx = KDBX.parse_file(
               ^^^^^^^^^^^^^^^^
 File "core.py", line 424, in parse_file  
   with open(filename, 'rb') as f:
        ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '\\\\my-org\\some-directory\\KeePass\\servers.kdbx'

-- Reply to this email directly or view it on GitHub: https://github.com/libkeepass/pykeepass/issues/394 You are receiving this because you are subscribed to this thread.

Message ID: @.***>