browser_cookie3
browser_cookie3 copied to clipboard
Script fails to run in MacOS crontab.
Everything is OK, if I manual run in the iterm.
Chrome 119.0.6045.199 (arm64) MacOS Sonama 14.1.2
But when I add the script in crontab, it fails with the errors:
* * * * * /Users/xxx/.virtualenvs/scripts/bin/python -u /Users/xxx/.virtualenvs/scripts/scripts/cron/xxx.py >> /tmp/xxx.log 2>&1
Traceback (most recent call last):
File "/Users/xxx/.virtualenvs/scripts/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 580, in _decrypt
decrypted = unpad(cipher.decrypt(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxx/.virtualenvs/scripts/lib/python3.11/site-packages/Cryptodome/Util/Padding.py", line 92, in unpad
raise ValueError("Padding is incorrect.")
ValueError: Padding is incorrect.
Traceback (most recent call last):
File "/Users/xxx/.virtualenvs/scripts/scripts/cron/xxx.py", line 5, in <module>
from browser_session import get, post
File "/Users/xxx/.virtualenvs/scripts/scripts/cron/yyy.py", line 5, in <module>
s.cookies = browser_cookie3.chrome()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxx/.virtualenvs/scripts/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 1161, in chrome
return Chrome(cookie_file, domain_name, key_file).load()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxx/.virtualenvs/scripts/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 515, in load
value = self._decrypt(value, enc_value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxx/.virtualenvs/scripts/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 586, in _decrypt
raise BrowserCookieError('Unable to get key for cookie decryption')
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption
If I change to Safary:
PermissionError: [Errno 1] Operation not permitted: '/Users/xxx/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies'
Same issue when I'm using Safari on macOS and it shows PermissionError.
I can't even manually sudo cd to the cookie path .../Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies.
running into the same problem, have you found any solutions?
running into the same problem, have you found any solutions?
no,I switch to use nodejs/playwright now 💔
I'm not familiar with MacOS but I assume that the script isn't running in the same environment as when you launch it manually. Perhaps it runs as a different user, different environment variables, or something? If the script works normally then I don't think this is a browser cookie issue
I had this same issue. I solved giving cron disk access.
On newer macOS versions, cron may need permissions:
- Open System Preferences → Security & Privacy → Privacy.
- Under Full Disk Access, add /usr/sbin/cron.