Borrow cookies from your browser's authenticated session for use in Python scripts.
Borrow cookies from your browser's authenticated session for use in Python scripts.
NB: Use
pipand
pythoninstead of
pip3and
python3if you're still on Python 2 and using pycookiecheat < v0.4.0. pycookiecheat >= v0.4.0 requires Python 3.5+, and may soon go to 3.6+.
pip3 install pycookiecheat
See #12. Chrome is now using a few different keyrings to store your
Chrome Safe Storagepassword, instead of a hard-coded password. Pycookiecheat doesn't work with most of these so far, and to be honest my enthusiasm for adding support for ones I don't use is limited. However, users have contributed code that seems to work with some of the recent Ubuntu desktops. To get it working, you may have to
sudo apt-get install libsecret-1-dev python-gi python3-gi, and if you're installing into a virtualenv (highly recommended), you need to use the
--system-site-packagesflag to get access to the necessary libraries.
Alternatively, some users have suggested running Chrome with the
--password-store=basicor
--use-mock-keychainflags.
git clone https://github.com/n8henrie/pycookiecheat.git
cd pycookiecheat
python3 -m venv venv
venv/bin/pip install -e .[dev]
from pycookiecheat import chrome_cookies import requestsurl = 'http://example.com/fake.html'
Uses Chrome's default cookies filepath by default
cookies = chrome_cookies(url) r = requests.get(url, cookies=cookies)
Use the
cookie_filekeyword-argument to specify a different filepath for the cookies-file:
chrome_cookies(url, cookie_file='/abspath/to/cookies')
Keep in mind that pycookiecheat defaults to looking for cookies for Chromium, not Google Chrome, so if you're using the latter, you'll need to manually specify something like
"/home/username/.config/google-chrome/Default/Cookies"as your
cookie_file.
I don't use Windows or have a PC, so I won't be adding support myself. Feel free to make a PR :)
cryptographymodule on OS X
(pycookiecheat <v0.4.0)
If you're getting this error and using Homebrew, then you need to follow the instructions for Building cryptography on OS X and
export LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include"and try again.
cryptographymodule on Linux
Please check the official cryptography docs. On some systems (e.g. Ubuntu), you may need to do something like
sudo apt-get install build-essential libssl-dev libffi-dev python-devprior to installing with
pip.
On KDE, Chrome defaults to using KDE's own keyring, KWallet. For pycookiecheat to support KWallet the
dbus-pythonpackage must be installed.
pip install git+https://github.com/n8henrie/[email protected]