Using Chrome's cookies in Python-Requests

TankorSmash picture TankorSmash · Jul 29, 2012 · Viewed 15k times · Source

I'm trying to log in to the http://www.steampowered.com website using the cookies I've got from my Chrome session.

Once I've grabbed all the cookie table's data, using the command SELECT * FROM cookie WHERE host_key LIKE '%steam%' and the column names: PRAGMA table_info(cookie) and sorted through all the data with a list comprehension, I don't know how to pass it all to requests so that the cookies become usable.

The request's docs say you need to pass in a dict, ie cookies={'cookies':'are_working'} but then some of the keys names overwrite each other, since a few of the names are : Steam_Language, though they're different hosts.

edit: Just found How to add cookie to existing cookielib CookieJar instance in Python? which might help me out, but I don't know how to format the Chrome cookies for cookielib

My question is: How do I pass several different sites worth of cookies to requests?

Answer

hoju picture hoju · Apr 14, 2015

I created a module to load cookies from Firefox.

Example usage with requests:

import requests
import browser_cookie
cj = browser_cookie.firefox()
r = requests.get(url, cookies=cj)