borisbabic/browser_cookie3

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\{user}\\AppData\\Local\\Temp\\tmp147jmo5w.sqlite'

faniAhmed opened this issue · 4 comments

I am facing this error while trying to get the cookies generated by MS Teams desktop app. I have added argument to send the cookie file path. I do not know if I am using it right or not. The following is the code

import browser_cookie3

c = browser_cookie3.chrome(cookie_file=r"C:\Users\Farhan Ahmed\AppData\Local\Packages\MicrosoftTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\EBWebView\Default\Network\Cookies")

for cookie in c:
    print(cookie.name, end=" ")
    print(cookie.value)

It gave the following error

Traceback (most recent call last):
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 315, in _decrypt
    return self._decrypt_windows_chromium(value, encrypted_value)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 306, in _decrypt_windows_chromium
    _, data = crypt_unprotect_data(encrypted_value)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 94, in crypt_unprotect_data
    raise RuntimeError('Failed to decrypt the cipher text with DPAPI')
RuntimeError: Failed to decrypt the cipher text with DPAPI

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 331, in _decrypt
    data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\Crypto\Cipher\_mode_gcm.py", line 567, in decrypt_and_verify
    self.verify(received_mac_tag)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\Crypto\Cipher\_mode_gcm.py", line 508, in verify   
    raise ValueError("MAC check failed")
ValueError: MAC check failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Farhan Ahmed\Desktop\code\Project 212\plugins-olek-test\delete.py", line 3, in <module>
    c = browser_cookie3.chrome(cookie_file=r"C:\Users\Farhan Ahmed\AppData\Local\Packages\MicrosoftTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\EBWebView\Default\Network\Cookies")
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 645, in chrome  
    return Chrome(cookie_file, domain_name, key_file).load()
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 291, in load    
    value = self._decrypt(value, enc_value)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 333, in _decrypt
    raise BrowserCookieError('Unable to get key for cookie decryption')
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption
Exception ignored in: <function ChromiumBased.__del__ at 0x000001AF3E5BC9D0>
Traceback (most recent call last):
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 257, in __del__ 
    os.remove(self.tmp_cookie_file)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\FARHAN~1\\AppData\\Local\\Temp\\tmpe_7voxra.sqlite'

I added a try except on this and the same above error occurred at some other place in code and I again added a try except block and the following error was thrown.

Traceback (most recent call last):
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 318, in _decrypt
    return self._decrypt_windows_chromium(value, encrypted_value)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 309, in _decrypt_windows_chromium
    _, data = crypt_unprotect_data(encrypted_value)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 94, in crypt_unprotect_data
    raise RuntimeError('Failed to decrypt the cipher text with DPAPI')
RuntimeError: Failed to decrypt the cipher text with DPAPI

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 334, in _decrypt
    data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\Crypto\Cipher\_mode_gcm.py", line 567, in decrypt_and_verify
    self.verify(received_mac_tag)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\Crypto\Cipher\_mode_gcm.py", line 508, in verify   
    raise ValueError("MAC check failed")
ValueError: MAC check failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Farhan Ahmed\Desktop\code\Project 212\plugins-olek-test\delete.py", line 4, in <module>
    c = browser_cookie3.chrome(cookie_file=r"C:\Users\Farhan Ahmed\AppData\Local\Packages\MicrosoftTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\EBWebView\Default\Network\Cookies")
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 651, in chrome  
    return Chrome(cookie_file, domain_name, key_file).load()
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 294, in load    
    value = self._decrypt(value, enc_value)
  File "C:\Users\Farhan Ahmed\AppData\Local\Programs\Python\Python310\lib\site-packages\browser_cookie3\__init__.py", line 336, in _decrypt
    raise BrowserCookieError('Unable to get key for cookie decryption')
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption

Thanks for helping in advance. I really need this to work, I hope someone can help me.

Try supplying the key_file argument:

chrome(cookie_file=<CookieFile>, key_file=<KeyFile>)

I wish I knew where the key file is stored

Generally, the key_file is located in C:\Users\<username>\AppData\Local<browser_name>\User Data\Local State

Good luck~

Thanks, but I need key for MS teams App Cookies, not the browser Cookies