Giter VIP home page Giter VIP logo

browser_cookie3's People

Contributors

0x79h avatar anasofiapaixao avatar antlu avatar arrnorets avatar balonik avatar borisbabic avatar brooksmcmillin avatar cam-barts avatar dechiad1 avatar decibyte avatar dlenski avatar drmikecrowe avatar easlice avatar estasney avatar jlyneu avatar josdion avatar kevin1018 avatar kmille avatar mendoor avatar moetayuko avatar nihilox avatar ppwwyyxx avatar rafiibrahim8 avatar rkhwaja avatar shatyuka avatar shrx avatar simon987 avatar skylion007 avatar tylerkrupicka avatar wimglenn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

browser_cookie3's Issues

error when load cookies

import browser_cookie3
cj = browser_cookie3.chrome()

Traceback (most recent call last):
File "", line 1, in
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 592, in chrome
return Chrome(cookie_file, domain_name, key_file).load()
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 382, in init
super().init(browser='Chrome', cookie_file=cookie_file, domain_name=domain_name, key_file=key_file, **args)
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 190, in init
self._add_key_and_cookie_file(**kwargs)
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init
.py", line 248, in __add_key_and_cookie_file
raise BrowserCookieError('Failed to find {} cookie'.format(self.browser))
browser_cookie3.BrowserCookieError: Failed to find Chrome cookie

cj = browser_cookie3.load()
Traceback (most recent call last):
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 268, in load
'FROM cookies WHERE host_key like "%{}%";'.format(self.domain_name))
sqlite3.OperationalError: no such column: secure

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 626, in load
for cookie in cookie_fn(domain_name=domain_name):
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 610, in edge
return Edge(cookie_file, domain_name, key_file).load()
File "E:\Work\btpn\env\lib\site-packages\browser_cookie3_init_.py", line 272, in load
'FROM cookies WHERE host_key like "%{}%";'.format(self.domain_name))
sqlite3.OperationalError: Could not decode to UTF-8 column 'encrypted_value' with text 'v10tb}obyM�(☻������L>��=����0e5���x�→▬s�♀Y;�Rfe�����4�u�'c��?�^z�+�▲-F�:��y�(��♣�►���Z��g����#=�↔�☻FP=lD�|A'`

BrowserCookieError: Can not find cookie file at: url

I get this error when I am trying to access cookies from a url

import browser_cookie3
cj=browser_cookie3.chrome(url)
with session() as c :
request=c.get(some_url, cookies=cj)

Is there anything wrong ?
Is it an issue with the package or the chrome browser

Module no longer functions with Firefox on Windows

Mozilla no longer stores profiles in the Program Files directory. They are now stored elsewhere.
%APPDATA%\Roaming\Mozilla\Firefox\Profiles%some_random_string%.default
Now stores the default profile for Windows. The path should be updated to reflect this change.

"ValueError: invalid padding byte" on Linux with google-chrome-stable-68

ENV:
Host: Fedora 28 x86_64
chrome version: google-chrome-stable-68.0.3440.106-1.x86_64
browser_cookies: browser-cookie3==0.6.4

reproduce steps:

  1. google-chrome-stable --user-data-dir=/tmp/browser_cookie3
  2. visit https://www.theverge.com/

before test, update browser_cookie3 code:

diff --git a/__init__.py b/__init__.py
index 1f404b8..6a13fde 100644
--- a/__init__.py
+++ b/__init__.py
@@ -180,7 +180,7 @@ class Chrome:
         if sys.platform == 'win32':
             return self._decrypt_windows_chrome(value, encrypted_value)
 
-        if value or (encrypted_value[:3] != b'v10'):
+        if value or (encrypted_value[:3] not in (b'v10', b'v11')):
             return value

test script:

import browser_cookie3
cj = browser_cookie3.chrome(cookie_file="/tmp/browser_cookie3/Default/Cookies", domain_name="theverge.com")

result:
$ python test_browser_cookie3.py

Traceback (most recent call last):
  File "test_browser_cookie3.py", line 3, in <module>
    cj = browser_cookie3.chrome(cookie_file="/tmp/browser_cookie3/Default/Cookies", domain_name="theverge.com")
  File "/home/test/.virtualenvs/chrome3/lib/python3.6/site-packages/browser_cookie3/__init__.py", line 277, in chrome
    return Chrome(cookie_file, domain_name).load()
  File "/home/test/.virtualenvs/chrome3/lib/python3.6/site-packages/browser_cookie3/__init__.py", line 157, in load
    value = self._decrypt(item[5], item[6])
  File "/home/test/.virtualenvs/chrome3/lib/python3.6/site-packages/browser_cookie3/__init__.py", line 195, in _decrypt
    decrypted += cipher.feed()
  File "/home/test/.virtualenvs/chrome3/lib/python3.6/site-packages/pyaes/blockfeeder.py", line 169, in feed
    result = self._final(self._buffer, self._padding)
  File "/home/test/.virtualenvs/chrome3/lib/python3.6/site-packages/pyaes/blockfeeder.py", line 77, in _block_final_decrypt
    return strip_PKCS7_padding(self.decrypt(data))
  File "/home/test/.virtualenvs/chrome3/lib/python3.6/site-packages/pyaes/util.py", line 58, in strip_PKCS7_padding
    raise ValueError("invalid padding byte")
ValueError: invalid padding byte

Error "browser_cookie3.BrowserCookieError: Can not find cookie file at: bitbucket.org" when get cookie from Chrome on Windows

import browser_cookie3
import sqlite3
cj = browser_cookie3.chrome('bitbucket.org')
r = requests.get(url, cookies=cj)
get_title(r.content)

I used the above code to get cookie of Bitbucket from Chrome. But I got the following error after I REPL to the 3rd line.
Environment: Windows 7 x64, Python 3.6, browser-cookie3 0.6.1, Chrome 59.0.3071.115 64bit

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python36\lib\site-packages\browser_cookie3\__init__.py", line 242, in chrome
    return Chrome(cookie_file, domain_name).load()
  File "c:\Python36\lib\site-packages\browser_cookie3\__init__.py", line 105, in __init__
    self.tmp_cookie_file = create_local_copy(cookie_file)
  File "c:\Python36\lib\site-packages\browser_cookie3\__init__.py", line 41, in create_local_copy
    raise BrowserCookieError('Can not find cookie file at: ' + cookie_file)
browser_cookie3.BrowserCookieError: Can not find cookie file at: bitbucket.org

Bug if service is None

Hello, thanks for that package!

When I tried to use it, I discovered a small bug, see the output.

It can easily be fixed by adding an if clause that checks if service is an actual object.

----> 1 b = browser_cookie3.chrome(domain_name='sdf')

/usr/lib/python3.8/site-packages/browser_cookie3/__init__.py in chrome(cookie_file, domain_name)
    463     domain name to only load cookies from the specified domain
    464     """
--> 465     return Chrome(cookie_file, domain_name).load()
    466
    467

/usr/lib/python3.8/site-packages/browser_cookie3/__init__.py in __init__(self, cookie_file, domain_name)
    177             # running Chrome on Linux
    178             # chrome linux is encrypted with the key peanuts
--> 179             my_pass = get_linux_pass().encode('utf8')
    180             iterations = 1
    181             self.key = PBKDF2(my_pass, self.salt,

/usr/lib/python3.8/site-packages/browser_cookie3/__init__.py in get_linux_pass(browser)
    123         service = Secret.Service.get_sync(flags)
    124
--> 125         gnome_keyring = service.get_collections()
    126         unlocked_keyrings = service.unlock_sync(gnome_keyring).unlocked
    127

Regards!

AttributeError: module 'browser_cookie3' has no attribute 'load'

Traceback (most recent call last):
File "app.py", line 5, in
cli.main()
File "/home/robert/.local/share/virtualenvs/nvidia-bot-EJANiOzL/lib/python3.8/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/home/robert/.local/share/virtualenvs/nvidia-bot-EJANiOzL/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/robert/.local/share/virtualenvs/nvidia-bot-EJANiOzL/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/robert/.local/share/virtualenvs/nvidia-bot-EJANiOzL/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/robert/.local/share/virtualenvs/nvidia-bot-EJANiOzL/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/robert/Applications/nvidia-bot/cli/cli.py", line 20, in decorator
func(*args, **kwargs)
File "/home/robert/Applications/nvidia-bot/cli/cli.py", line 52, in nvidia
nv = NvidiaBuyer(gpu, locale, test, interval)
File "/home/robert/Applications/nvidia-bot/stores/nvidia.py", line 76, in init
self.cj = browser_cookie3.load(".nvidia.com")
AttributeError: module 'browser_cookie3' has no attribute 'load'

Chrome timestamps are not correctly read

Google Chrome uses timestamp which are not in the Unix epoch format. The result is that the cookiejar contains cookies with meaningless timestamps. I think they should be recomputed to a usable value.
The main issue is if I read the cookiejar from my chrome profile and then try to save it to a file using pythons standard LWPCookieJar.save
This raises an exception:

  File "C:\Program Files\Python36\lib\http\cookiejar.py", line 1880, in save
    f.write(self.as_lwp_str(ignore_discard, ignore_expires))
  File "C:\Program Files\Python36\lib\http\cookiejar.py", line 1867, in as_lwp_str
    r.append("Set-Cookie3: %s" % lwp_cookie_str(cookie))
  File "C:\Program Files\Python36\lib\http\cookiejar.py", line 1828, in lwp_cookie_str
    time2isoz(float(cookie.expires))))
  File "C:\Program Files\Python36\lib\http\cookiejar.py", line 104, in time2isoz
    dt = datetime.datetime.utcfromtimestamp(t)

See more here: https://stackoverflow.com/questions/20458406/what-is-the-format-of-chromes-timestamps

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'

OS: windows10
Browser: Chrome

I do not know how to reproduce this proble. I meet the same problem several month ago. At that time, I fixed it by clearning all data in browser. This should be related to browser_cookie3 since the problem is shown by the most simple code shown in the introduciton.
I tried to reboot OS, browser.

(By the way, I do not have admin permisson to this PC)

related error reports:

Exception ignored in: <function Chrome.__del__ at 0x0000024764E59730>
Traceback (most recent call last):
  File "c:\users\{user}\appdata\local\continuum\miniconda3\lib\site-packages\browser_cookie3\__init__.py", line 148, 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\\{user}\\AppData\\Local\\Temp\\tmp2hb41qrw.sqlite'
Exception ignored in: <function Chrome.__del__ at 0x0000024764E59730>
Traceback (most recent call last):
  File "c:\users\{user}\appdata\local\continuum\miniconda3\lib\site-packages\browser_cookie3\__init__.py", line 148, 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\\{user}\\AppData\\Local\\Temp\\tmpot3jbe_8.sqlite'

How to use browser_cookie3 with Selenium?

The CookieJar format works fine with Requests, but how can I use it with Selenium?

My script:

import browser_cookie3
from selenium import webdriver

url = "https://homeworker.li/todo"

cj = browser_cookie3.firefox(domain_name='homeworker.li')

driver = webdriver.PhantomJS()
driver.get(url)

driver.add_cookie(cj)

html2 = driver.execute_script("return document.documentElement.innerHTML;")

print(html2)

The traceback:

Traceback (most recent call last):
File "C:/Users/PycharmProjects/Scraping/Homeworker.py", line 11, in
driver.add_cookie(cj)
File "C:\Users\PycharmProjects\Scraping\ven\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 894, in add_cookie
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
File "C:\Users\PycharmProjects\Scraping\ven\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\PycharmProjects\Scraping\ven\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 372, in execute
data = utils.dump_json(params)
File "C:\Users\PycharmProjects\Scraping\ven\lib\site-packages\selenium\webdriver\remote\utils.py", line 33, in dump_json
return json.dumps(json_struct)
File "C:\Program Files\Python38\lib\json_init_.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Program Files\Python38\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Program Files\Python38\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Program Files\Python38\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type CookieJar is not JSON serializable

How can I convert the CookieJar to JSON? I would appreciate any help.

Raspberry 10.4 ValueError: Namespace Secret not available

File "/home/pi/.local/lib/python3.7/site-packages/browser_cookie3/init.py", line 117, in get_linux_pass
gi.require_version("Secret", "1")
File "/usr/lib/python3/dist-packages/gi/init.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Secret not available

A module must be missing or outdated but I can't figure out what.

Load() overwrites cookie if it exists in multiple browsers

Example:
JSESSION cookie exists for www.example.com in both chrome and firefox. browser_cookie3.load("www.example.com") will first get the cookie from chrome, then overwrite it with the one from firefox.

This will happen in the order the browsers are checked: chrome, chromium, opera, edge, firefox.

If you generate the cookie once in a later browser then start using any earlier one, you will end up with the older cookie no matter how many times you generate it in earlier ones. This will continue until the cookie is cleared from the later browser.

Possible solutions:

  • Check the expiration time for the cookie in the current loop and only overwrite if it is later than the existing cookie.
  • Provide both cookies and allow caller to pick the one they want (may not be possible while using stdlib cookiejar methods).
  • Change nothing, but warn about this behaviour for the method so caller can decide to implement their own multi-browser loop order

File contains no section headers

File contains no section headers.
file: 'C:\\Users\\miche\\AppData\\Roaming\\Mozilla\\Firefox\\profiles.ini', line: 1
'ÿþ[\x00I\x00n\x00s\x00t\x00a\x00l\x00l\x003\x000\x008\x000\x004\x006\x00B\x000\x00A\x00F\x004\x00A\x003\x009\x00C\x00B\x00]\x00\n'
  File "\browsercookie3\__init__.py", line 356, in get_default_profile
    config.read(profiles_ini_path)
  File "\browsercookie3\__init__.py", line 394, in find_cookie_file
    cookie_files = glob.glob(os.path.join(Firefox.get_default_profile(user_data_path), 'cookies.sqlite')) \
  File "\browsercookie3\__init__.py", line 327, in __init__
    cookie_file = cookie_file or self.find_cookie_file()
  File "\browsercookie3\__init__.py", line 470, in firefox
    return Firefox(cookie_file, domain_name).load()

This happens only with Firefox, deleting profiles.ini solves the issue temporarily.

Request: Save Cookies Back to Chrome

Hell all! Great update for the 80+. I recompiled myself before finding this one. However, I would like to ask if there is currently, or plans to be, a way to inject cookies directly into the file via this library.

I am working on automation with the server changing the cookie after every action. After the automation is done, i would like to take the most recent cookie and save it back to the file so when i go back to my chrome browser, it has the newest cookie.

Its late here, so if you could already do that, sorry, help a brother out!

path should be string, bytes, os.PathLike or integer, not NoneType

Platform: Manjaro Linux 20.1.1

I'm trying to read cookies from chrome, but I keep getting this error:

Traceback (most recent call last):
File "/home/andrea/test/cookies_test.py", line 4, in <module>
    browser_cookie3.chrome()
  File "/usr/lib/python3.8/site-packages/browser_cookie3/__init__.py", line 468, in chrome
    return Chrome(cookie_file, domain_name, key_file).load()
  File "/usr/lib/python3.8/site-packages/browser_cookie3/__init__.py", line 228, in __init__
    self.tmp_cookie_file = create_local_copy(cookie_file)
  File "/usr/lib/python3.8/site-packages/browser_cookie3/__init__.py", line 45, in create_local_copy
    if os.path.exists(cookie_file):
  File "/usr/lib/python3.8/genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

The code is

import browser_cookie3

browser_cookie3.chrome()

and nothing else. I also get the error when I use browser_cookie3.load() but not with browser_cookie3.firefox()
I can't understand where that null path comes from, but I suspect that it may be because of this assignment in browser_cookie3/__init__.py :

            paths = map(os.path.expanduser, [
                '~/.config/google-chrome/Default/Cookies',
                '~/.config/chromium/Default/Cookies',
                '~/.config/google-chrome-beta/Default/Cookies'
            ])

because I can't find those files/folders in my filesystem, so the module may be making some bad assumptions on how my chrome installation works

Chrome cookies table changed in version 66

Chrome version 66 (in OSX) has changed the name of the "secure" column in the cookies table to "is_secure", so Chrome.load() fails with (sqlite3.OperationalError: no such column: secure).

Culprit:
cur.execute('SELECT host_key, path, secure, expires_utc, name, value, encrypted_value '
'FROM cookies WHERE host_key like "%{}%";'.format(self.domain_name))

File encoding error when calling browser_cookie3.load()

  File "C:\Python39\lib\site-packages\browser_cookie3\__init__.py", line 502, in load
    for cookie in cookie_fn(domain_name=domain_name):
  File "C:\Python39\lib\site-packages\browser_cookie3\__init__.py", line 492, in firefox
    return Firefox(cookie_file, domain_name).load()
  File "C:\Python39\lib\site-packages\browser_cookie3\__init__.py", line 347, in __init__
    cookie_file = cookie_file or self.find_cookie_file()
  File "C:\Python39\lib\site-packages\browser_cookie3\__init__.py", line 414, in find_cookie_file
    cookie_files = glob.glob(os.path.join(Firefox.get_default_profile(user_data_path), 'cookies.sqlite')) \
  File "C:\Python39\lib\site-packages\browser_cookie3\__init__.py", line 376, in get_default_profile
    config.read(profiles_ini_path)
  File "C:\Python39\lib\configparser.py", line 697, in read
    self._read(fp, filename)
  File "C:\Python39\lib\configparser.py", line 1082, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: 'C:\\Users\\Masterisk\\AppData\\Roaming\\Mozilla\\Firefox\\profiles.ini', line: 1
'ÿþ[\x00G\x00e\x00n\x00e\x00r\x00a\x00l\x00]\x00\n'

This is occurring because the Firefox profiles.ini is encoded in utf-16. -- I'm unsure if this is a recent change or an error of some sort.

Line 492 in browser_cookie3\__init__.py calls "config.read(profiles_ini_path)"
config.read has an optional argument for encoding
if you use "config.read(profiles_ini_path, encoding='utf-16')" this works.

For my own use I've changed line 492 to be as follows:

try:
    config.read(profiles_ini_path)
except configparser.MissingSectionHeaderError:
    config.read(profiles_ini_path, encoding='utf-16')

There is probably a better way to fix this with detecting the file encoding with the chardet module.
But this should be a step in the right direction if this isn't just a weird issue with my environment.

chrome failed

Version 80.0.3987.122 (Official Build) (64-bit)

In [32]: cj = browser_cookie3.chrome()

ValueError Traceback (most recent call last)
in
----> 1 cj = browser_cookie3.chrome()

/mnt/os/opt/anaconda3/lib/python3.7/site-packages/browser_cookie3/init.py in chrome(cookie_file, domain_name)
463 domain name to only load cookies from the specified domain
464 """
--> 465 return Chrome(cookie_file, domain_name).load()
466
467

/mnt/os/opt/anaconda3/lib/python3.7/site-packages/browser_cookie3/init.py in load(self)
267 expires = expires.timestamp()
268
--> 269 value = self._decrypt(item[5], item[6])
270 c = create_cookie(host, path, secure, expires, name, value)
271 cj.set_cookie(c)

/mnt/os/opt/anaconda3/lib/python3.7/site-packages/browser_cookie3/init.py in _decrypt(self, value, encrypted_value)
320 decrypted = cipher.feed(encrypted_value[:encrypted_value_half_len])
321 decrypted += cipher.feed(encrypted_value[encrypted_value_half_len:])
--> 322 decrypted += cipher.feed()
323 return decrypted.decode("utf-8")
324

/mnt/os/opt/anaconda3/lib/python3.7/site-packages/pyaes/blockfeeder.py in feed(self, data)
167 # Finalize; process the spare bytes we were keeping
168 if data is None:
--> 169 result = self._final(self._buffer, self._padding)
170 self._buffer = None
171 return result

/mnt/os/opt/anaconda3/lib/python3.7/site-packages/pyaes/blockfeeder.py in _block_final_decrypt(self, data, padding)
75 def _block_final_decrypt(self, data, padding = PADDING_DEFAULT):
76 if padding == PADDING_DEFAULT:
---> 77 return strip_PKCS7_padding(self.decrypt(data))
78
79 if padding == PADDING_NONE:

/mnt/os/opt/anaconda3/lib/python3.7/site-packages/pyaes/util.py in strip_PKCS7_padding(data)
56
57 if pad > 16:
---> 58 raise ValueError("invalid padding byte")
59
60 return data[:-pad]

ValueError: invalid padding byte

Load cookies from alternative Google Chrome profiles

This library is super useful however it seems to be completely unable to retrieve cookies from alternative Google Chrome profiles. As someone who separates private and work browsing using Google Chrome's profile system this feature would be very much appreciated.

While ideally I would be able to select which profile this library selects I would appreciate just checking all profiles when the user requests cookies from all compatible browsers.

Thanks for the development!

Chrome cookie failed on linux

browser_cookie3 can not load cookies from Chrome on Linux. It throws following exception:

Traceback (most recent call last):
  File "/home/ibrahim/Workspace/BrowserCookie/bc.py", line 2, in <module>
    c = bc3.chrome(domain_name='facebook.com')
  File "/home/ibrahim/.local/lib/python3.6/site-packages/browser_cookie3/__init__.py", line 485, in chrome
    return Chrome(cookie_file, domain_name, key_file).load()
  File "/home/ibrahim/.local/lib/python3.6/site-packages/browser_cookie3/__init__.py", line 177, in __init__
    my_pass = get_linux_pass(name)
  File "/home/ibrahim/.local/lib/python3.6/site-packages/browser_cookie3/__init__.py", line 117, in get_linux_pass
    gi.require_version("Secret", "1")
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 130, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Secret not available

OS: elementary OS 5.1.7 Hera x86_64
Chrome Version: 87.0.4280.88 (Official Build) (64-bit)

failed to find firefox cookie in firefox 72.0.1

In Firefox 72.0.1 profiles.ini got propped up to the parent of Profiles, with relative paths being prepended by 'Profiles/', and the profiles.ini Default=1 flag gets ignored when it contradicts the value of the [Install<id>] section, causing browser-cookie3 to be unable to find the cookie file.

sqlite3.OperationalError: no such column: secure in Chome 73

'FROM cookies WHERE host_key like "%{}%";'.format(self.domain_name))
sqlite3.OperationalError: no such column: secure
Exception ignored in: <function Chrome.del at 0x000001E601E170D0

In the init file at line 87. changing the secure to is_secure fixes the issues in many newer version of browsers.

Fix:
cur.execute('SELECT host_key, path, is_secure, expires_utc, name, value, encrypted_value '
'FROM cookies WHERE host_key like "%{}%";'.format(self.domain_name))

Python 3.9 installation problem

I updated my python installation from 3.8.x to 3.9.0. After that I tried to install browser_cookie3 for the new python but I am getting error.

ERROR: Command errored out with exit status 1:
     command: 'c:\users\laxar\appdata\local\programs\python\python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\laxar\\AppData\\Local\\Temp\\pip-install-c4hdj2qm\\pycryptodome\\setup.py'"'"'; __file__='"'"'C:\\Users\\laxar\\AppData\\Local\\Temp\\pip-install-c4hdj2qm\\pycryptodome\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\laxar\AppData\Local\Temp\pip-pip-egg-info-saxvw177'
         cwd: C:\Users\laxar\AppData\Local\Temp\pip-install-c4hdj2qm\pycryptodome\
    Complete output (20 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\laxar\AppData\Local\Temp\pip-install-c4hdj2qm\pycryptodome\setup.py", line 457, in <module>
        set_compiler_options(package_root, ext_modules)
      File "C:\Users\laxar\AppData\Local\Temp\pip-install-c4hdj2qm\pycryptodome\compiler_opt.py", line 341, in set_compiler_options
        clang = compiler_is_clang()
      File "C:\Users\laxar\AppData\Local\Temp\pip-install-c4hdj2qm\pycryptodome\compiler_opt.py", line 251, in compiler_is_clang
        return test_compilation(source, msg="clang")
      File "C:\Users\laxar\AppData\Local\Temp\pip-install-c4hdj2qm\pycryptodome\compiler_opt.py", line 82, in test_compilation
        objects = compiler.compile([fname], extra_postargs=extra_cc_options)
      File "c:\users\laxar\appdata\local\programs\python\python39\lib\distutils\_msvccompiler.py", line 323, in compile
        self.initialize()
      File "c:\users\laxar\appdata\local\programs\python\python39\lib\distutils\_msvccompiler.py", line 220, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "c:\users\laxar\appdata\local\programs\python\python39\lib\site-packages\setuptools\msvc.py", line 314, in msvc14_get_vc_env
        return _msvc14_get_vc_env(plat_spec)
      File "c:\users\laxar\appdata\local\programs\python\python39\lib\site-packages\setuptools\msvc.py", line 268, in _msvc14_get_vc_env
        raise distutils.errors.DistutilsPlatformError(
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    Testing support for clang
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I have 2015-2019 redistributable installed.
Is it not compatible with 3.9?

domain filter not working w/ Firefox

cj = browser_cookie3.firefox(domain_name=a_domain); len(cj) -> 62

That seemed big, so I added this test

len([x for x in cj if a_domain in x.domain]) -> 11

I also checked for a domain of '' and found none

I looked at your code which appears reasonable, but clearly isn't doing what I expected. The scraping that I want to do works with either set of cookies, but I'm a bit OCD, so I have added a post-filter in my own code to send only the needed ones.

Firefox version: 75.0 (64-bit)
MacOS: version Catalina 10.15.4

Use pycryptodomex instead of pycryptodome

pycryptodome is to be used in place of PyCrypto and is to be used only in a virtualenv.

PyCrypto and pycryptodomex can coexist but pycryptodome and pycrypto cannot.

https://stackoverflow.com/a/48175912/7732434

Also:

Docstrings should use triple double quotes not tripple single quotes. You could also put the docstrings of some functions on one line instead of two.

Line https://github.com/borisbabic/browser_cookie3/blob/master/__init__.py#L221has an extra line.

Chrome 80.0.3987 and above.

2020-02-04 Chrome updated to 80.0.3987 and browser_cookie3 can't get cookies from chrome now (Windows).
Is it possible to fix?

from pysqlite2 import dbapi2 as sqlite3 or ModuleNotFoundError No module named 'pysqlite2'

win7,32-bit, anaconda env-py3.7 prompt:
1、ModuleNotFoundError: No module named 'pysqlite2'
2、from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found

resolvent:
Go to the official website of SQLite3( https://www.sqlite.org/download.html )Download the corresponding plug-ins according to your own system and bits (32-bit or 64 bit). After downloading, unzip and copy the two files (SQLite3. Def and SQLite3. DLL) to the DLLs directory of Anaconda or the DLLs directory of your own virtual environment.

Issue Getting Chrome Cookies - Windows 7, Chrome 79.0.3945.117

Here is the error I'm getting trying to import Chrome cookies. test.py is 2 lines

import browser_cookie3 cookies = browser_cookie3.chrome()

Here is the error I get. It was working before, though I haven't run the script using this call in a while so I'm not sure exactly when it broke.

Traceback (most recent call last):
File "test.py", line 3, in
cookies = browser_cookie3.chrome()
File "venv\lib\site-packages\browser_cookie3_init_.py", line 351, in chrome
return Chrome(cookie_file, domain_name).load()
File "venv\lib\site-packages\browser_cookie3_init_.py", line 180, in load
expires = expires.timestamp()
OSError: [Errno 22] Invalid argument
Exception ignored in: <function Chrome.del at 0x00000000035DBD90>
Traceback (most recent call last):
File "venv\lib\site-packages\browser_cookie3_init_.py", line 150, 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: '~\AppData\Local\Temp\tmprvc6vp3c.sqlite'

browser_cookie3.firefox() still seems to work as expected.

raise BrowserCookieError('Failed to find Chrome cookie')

hi
I have this error (raise BrowserCookieError('Failed to find Chrome cookie')), and I use:
windows 7
browser_cookie3 0.10.0
python 3.7.4

the code was:

import browser_cookie3
import requests

cookiejar = browser_cookie3.chrome()
resp = requests.get('https://www.google.com/', cookies=cookiejar)
print(resp.content)

but if I tried browser_cookie3.firfox() I have no error and it work just fine.
so I tried Richard Penman browsercookie and the code didn't give me any error but it didn't work.

thanks

Doesn't work with latest Chrome version

I'm on windows 10 20H2 running Chrome version 90.0.4430.85, it worked fine while I was in 89.0.4389.128.

Traceback (most recent call last): File "C:\Users\Gistix\AppData\Local\Programs\Python\Python37\lib\site-packages\browser_cookie3\__init__.py", line 267, in load cur.execute('SELECT host_key, path, secure, expires_utc, name, value, encrypted_value ' sqlite3.OperationalError: no such column: secure

OverflowError and OSError for chrome

It raises OverflowError for cookie with epoch_start = 1601-01-01 00:00:00 19055414 days

Traceback (most recent call last):
  File "F:/dev/hdchinaLogin/login.py", line 5, in <module>
    cj = browser_cookie3.chrome()
  File "C:\Users\dzhuang\AppData\Roaming\Python\Python37\site-packages\browser_cookie3\__init__.py", line 345, in chrome
    return Chrome(cookie_file, domain_name).load()
  File "C:\Users\dzhuang\AppData\Roaming\Python\Python37\site-packages\browser_cookie3\__init__.py", line 173, in load
    expires = epoch_start + delta
OverflowError: date value out of range

Also, it raise OSError for expires without timestamp.

Traceback (most recent call last):
  File "F:/dev/hdchinaLogin/login.py", line 5, in <module>
    cj = browser_cookie3.chrome()
  File "C:\Users\dzhuang\AppData\Roaming\Python\Python37\site-packages\browser_cookie3\__init__.py", line 345, in chrome
    return Chrome(cookie_file, domain_name).load()
  File "C:\Users\dzhuang\AppData\Roaming\Python\Python37\site-packages\browser_cookie3\__init__.py", line 174, in load
    expires = expires.timestamp()
OSError: [Errno 22] Invalid argument

ValueError: invalid padding byte

when I use in Mac OS
I just call

cj = browser_cookie3.chrome()

the system ask me the python to visit the keychain
the it raise en error

Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_run_in_console.py", line 69, in
globals = run_file(file, None, None)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_run_in_console.py", line 29, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/xx/PycharmProjects/untitled1/login.py", line 12, in
operate.xin()
here is I use browse_cookies.chrome()
File "/Users/xx/PycharmProjects/untitled1/discuz.py", line 107, in xin
cookies = browser_cookie3.chrome()
File "/usr/local/lib/python3.5/site-packages/browser_cookie3/init.py", line 193, in chrome
return Chrome(cookie_file, domain_name).load()
File "/usr/local/lib/python3.5/site-packages/browser_cookie3/init.py", line 91, in load
value = self._decrypt(item[5], item[6])
File "/usr/local/lib/python3.5/site-packages/browser_cookie3/init.py", line 120, in _decrypt
decrypted += cipher.feed()
File "/usr/local/lib/python3.5/site-packages/pyaes/blockfeeder.py", line 169, in feed
result = self._final(self._buffer, self._padding)
File "/usr/local/lib/python3.5/site-packages/pyaes/blockfeeder.py", line 77, in _block_final_decrypt
return strip_PKCS7_padding(self.decrypt(data))
File "/usr/local/lib/python3.5/site-packages/pyaes/util.py", line 58, in strip_PKCS7_padding
raise ValueError("invalid padding byte")
ValueError: invalid padding byte

OSError: [Errno 22] Invalid argument when try browser_cookie3.chrome

when i tried to load cookie from the Chromium Edge , it have the error

browser_cookie3.chrome(cookie_file='C:\\Users\\JX\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default\\Cookies')

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "G:\Wpy\WPy64-3810\python-3.8.1.amd64\lib\site-packages\browser_cookie3\__init__.py", line 351, in chrome
    return Chrome(cookie_file, domain_name).load()
  File "G:\Wpy\WPy64-3810\python-3.8.1.amd64\lib\site-packages\browser_cookie3\__init__.py", line 177, in load
    expires = expires.timestamp()
OSError: [Errno 22] Invalid argument

My Env is Winpython64,python3.8.1 at Win10 x64

but it works when I tried

browser_cookie3.chrome(cookie_file='C:\\Users\\JX\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default\\Cookies', domain_name="github.com")

and it works with browser_cookie3.firefox()

'Failed to find Firefox cookie' in firefox 68

browser-cookie3 fails to find the cookie store in Firefox 68.3.0esr 32-bit, running on Windows 10 Enterprise 64-bit. In that system, the cookie store is actually located under C:\Users<username>\AppData\Roaming\Mozilla\Firefox\Profiles<username> which is not being checked by the library.

Get empty cookies

In [1]: import browser_cookie3                                                                                                         
In [2]: cj = browser_cookie3.chrome(domain_name='github.com')                                                                          
In [3]: for c in cj: 
    ...:     print(c) 
    ...:     print(c.value) 
    ...:                                                                                                                                
<Cookie _ga= for .github.com/>

<Cookie _gat= for .github.com/>

<Cookie _gid= for .github.com/>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.