thewh1teagle / rookie Goto Github PK
View Code? Open in Web Editor NEWLoad cookies from your web browsers
Home Page: https://crates.io/crates/rookie
License: MIT License
Load cookies from your web browsers
Home Page: https://crates.io/crates/rookie
License: MIT License
Hello, really grateful for your software, it's saved me a lot of time. However, there's a minor issue – it doesn't work properly with Octo Browser (https://octobrowser.net/). I've come up with a quick fix that addresses this problem, but I've never worked with Rust before, and I'd appreciate if you (the author) could resolve this bug related to cookie unloading via Python bindings from Octo Browser. Here's the link to my commit that resolves this issue with Octo Browser (Chromium): igorank@859f6d7
RUST_BACKTRACE=1
environment variable to display a backtraceChromium
Unlocking chrome database, it may take a while (sometimes up to minute)
thread '<unnamed>' panicked at rookie-rs\src\browser\chromium.rs:89:36:
range end index 3 out of range for slice of length 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Exception in thread Thread-1:
File "C:\Users\work\Documents\Projects\fb-multi-tasker\cookie_manager.py", line 15, in _load_cookies_from_db
cookies = rookiepy.any_browser(db_path=db_path, key_path=key_path, domains=None)
pyo3_runtime.PanicException: range end index 3 out of range for slice of length 1
Consider the following python script (using v0.2.7):
import browser_cookie3, rookiepy
print('browser_cookie3:')
for c in browser_cookie3.firefox(domain_name='test.wikipedia.org'):
print(c.name, c.expires)
print('\nrookiepy:')
for c in rookiepy.firefox(['test.wikipedia.org']):
print(c.name, c.expires)
prints the following:
browser_cookie3:
testwikiss0-UserID 1728238484
testwikiUserID 1728238484
testwikiss0-UserName 1728238484
testwikiUserName 1728238484
WMF-Last-Access 1699444800
WMF-DP 1696723200
NetworkProbeLimit 1696706087
testwikiSession None
ss0-testwikiSession None
testwikimwuser-sessionId None
rookiepy:
testwikiss0-UserID 1728238484000
testwikiUserID 1728238484000
testwikiss0-UserName 1728238484000
testwikiUserName 1728238484000
WMF-Last-Access 1699444800000
WMF-DP 1696723200000
NetworkProbeLimit 1696706087000
testwikiSession 2012062492654
ss0-testwikiSession 2012062492654
testwikimwuser-sessionId 2012062492654
Note that expiry values returned by rookiepy are 1000 times greater than the ones in browser_cookie3. (they are in milliseconds instead of the expected seconds)
Also, for the last three items, rookiepy has returned 2012062492654
instead of None
. This currently does not cause issue, because it is in milliseconds, but if we convert values to second then the cookie is expired.
the function simply runs over all the available browsers and picks the first one that is found for a specific domain.
On Firefox setups with an empty "Profile0" profile (happens when some other profile is the default):
PanicException: called `Result::unwrap()` on an `Err` value: cant find any brave cookies file
You have to parse the [Install...]
section in the profiles.ini
file and find out the actual profile to use. Ideally one could optionally select a specific profile.
firefox --ProfileManager
google.com
. Cookies are stored.~ ❯ python -m venv .test
~ ❯ .test/bin/pip install rookiepy
Collecting rookiepy
Obtaining dependency information for rookiepy from https://files.pythonhosted.org/packages/48/51/09a1ae45a89414a9d5c41017dd41633cfe218211e1e3e05db5ccc6814d4e/rookiepy-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata
Downloading rookiepy-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (599 bytes)
Downloading rookiepy-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.7/3.7 MB 5.4 MB/s eta 0:00:00
Installing collected packages: rookiepy
Successfully installed rookiepy-0.3.3
~ ❯ .test/bin/pip install ipython
[...]
~ ❯ .test/bin/ipython
Python 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.18.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import rookiepy
In [2]: cookies = rookiepy.firefox(["google.com"])
thread '<unnamed>' panicked at bindings/python/src/lib.rs:33:44:
called `Result::unwrap()` on an `Err` value: cant find any brave cookies file
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---------------------------------------------------------------------------
PanicException Traceback (most recent call last)
Cell In[2], line 1
----> 1 cookies = rookiepy.firefox(["google.com"])
PanicException: called `Result::unwrap()` on an `Err` value: cant find any brave cookies file
Firefox
No response
Hello,
When using rookiepy to retrieve the sessionid cookie for a website, it directly expires the session, so I can't use it to login with my script. I use Microsoft Edge and the cookie expires when I use load() or edge() methods, even if I don't use the cookie in a request.
Is it a problem with rookiepy or with the website I'm trying to connect ? It's weird because with browser_cookie3, before the chromium update, it worked perfectly.
Thanks
as the title says do please include the domain i'm using load function for some reason it's missing the domain variable.
RUST_BACKTRACE=1 cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Running target/debug/cookie_helper
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: decrypt_encrypted_value failed', src/main.rs:5:56
stack backtrace:
0: rust_begin_unwind
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
1: core::panicking::panic_fmt
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
2: core::result::unwrap_failed
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1651:5
3: core::result::Result<T,E>::unwrap
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1076:23
4: cookie_helper::main
at ./src/main.rs:5:32
5: core::ops::function::FnOnce::call_once
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with RUST_BACKTRACE=full
for a verbose backtrace.
use rookie::{self, common::enums::Cookie};
fn main() {
let domains = Some(vec!["google.com"]); // set to None to get all
let cookies: Vec = rookie::chrome(domains).unwrap();
println!("{cookies:?}");
}
1.cargo run
Chrome
No response
In config.rs
, the Chrome config data_paths
list is lacking additional patterns,
"%LOCALAPPDATA%/Google/Chrome{channel}/User Data/Profile */Network/Cookies", /*notice the s at the end*/
...
"%APPDATA%/Google/Chrome{channel}/User Data/Profile */Network/Cookies"
I have witnessed first-hand this file being created instead of Cookie
for Chrome 118.0.5993.71 with a signed-in google account attached. I would consider this a bug over a feature request because all the rest of the Chromium-based browser configs have it already. I can submit a PR if you want it, but the solution in this case is so trivial I don't think its worth the extra effort rather than rolling this fix into the next update.
Profile n/
Cookies
instead of Cookie
under Profile n/Network/
.Chrome
No response
At this time, I have observed in Chrome, 118.0.5993.71 at the very least, that cookies set as Expiry=Session do what they say on the tin: they are not stored within the database file at anytime.
I am fairly certain this is a unsolvable problem within the confines of the "reading the Cookies
database file" solution that this project and those like it rely on to provide functionality, however, I think it would be worth opening at issue on this, if for no other reason than to direct future users to this, as this will certainly become a regularly-asked question. I have yet to see mention of this fundamental gap in functionality mentioned for this project in the documentation, much to the dismay of those who embark on using this code to solve their problem, only to find their one problem cannot be solved by these means.
For said future developers with this problem: my one recommendation to you is to write a browser extension to read the cookie when it is sent by the server, if there is no other option (like submitting a login form instead, which I suppose you've already considered by now).
If you don't think this issue will have any benefit to you/this project, feel free to close it, no hard feelings. :)
It seems like python 3.12 wheels are only available for linux: https://pypi.org/project/rookiepy/#files
Is it possible to provide python 3.12 wheels on windows and macOS? Thanks.
Edit:
Seems like python3.12 was not present on the runner for the latest release: https://github.com/thewh1teagle/rookie/actions/runs/6435145142/job/17475799007#step:4:247
Github runner image with python 3.12 is still prerelease (https://github.com/actions/runner-images/releases/tag/win22%2F20231005.1), so your runner did not have python3.12 on it
You can wait about 1 week for github runner with python 3.12 to be released and fully rolled out (https://github.com/actions/runner-images#available-images), by then python 3.12 wheels should be built the next time you run github action without further modifications, or you can modify github action to do this without further waiting:
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
allow-prereleases: true
How to specify cookie_file, key_file and domain_name in Rookie,
In browser_cookie3 I can do that like this:
browser_cookie3.any_browser(cookie_file='something', domain_name="something", key_file='something'),
but in rookie it doesn't work.
Unfortunately, apparently this lib is also broken and does not work with chrome because decrypt.
Trace:
cookies = rookiepy.chrome()
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "cant decrypt value"', src/lib.rs:85:43
...
PanicException: called `Result::unwrap()` on an `Err` value: "cant decrypt value"
Arch Linux, google-chrome (Stable Channel) 117.0.5938.132-1
(from aur)
Currently the Error
type used is Box<dyn Error>
which cannot be known at compilation time, which prevents using the ?
operator within a method that returns Result
.
Using a crate such as thiserror
or even anyhow
if you'd rather not have strict Error types would solve this and make using this library easier.
error[E0277]: the size for values of type `dyn std::error::Error` cannot be known at compilation time
--> src\lib.rs:29:44
|
29 | let cookies = rookie::load(domains)?;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn std::error::Error`
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Yeet<E>>>
<Result<T, F> as FromResidual<Result<Infallible, E>>>
= note: required for `Box<dyn std::error::Error>` to implement `std::error::Error`
= note: required for `anyhow::Error` to implement `From<Box<dyn std::error::Error>>`
= note: required for `Result<SpotifyLyrics, anyhow::Error>` to implement `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>`
error[E0277]: `dyn std::error::Error` cannot be sent between threads safely
--> src\lib.rs:29:44
|
29 | let cookies = rookie::load(domains)?;
| ^ `dyn std::error::Error` cannot be sent between threads safely
|
= help: the trait `Send` is not implemented for `dyn std::error::Error`
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Yeet<E>>>
<Result<T, F> as FromResidual<Result<Infallible, E>>>
= note: required for `Unique<dyn std::error::Error>` to implement `Send`
note: required because it appears within the type `Box<dyn Error>`
--> C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\boxed.rs:195:12
|
195 | pub struct Box<
| ^^^
= note: required for `anyhow::Error` to implement `From<Box<dyn std::error::Error>>`
= note: required for `Result<SpotifyLyrics, anyhow::Error>` to implement `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>`
error[E0277]: `dyn std::error::Error` cannot be shared between threads safely
--> src\lib.rs:29:44
|
29 | let cookies = rookie::load(domains)?;
| ^ `dyn std::error::Error` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `dyn std::error::Error`
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Yeet<E>>>
<Result<T, F> as FromResidual<Result<Infallible, E>>>
= note: required for `Unique<dyn std::error::Error>` to implement `Sync`
note: required because it appears within the type `Box<dyn Error>`
--> C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\boxed.rs:195:12
|
195 | pub struct Box<
| ^^^
= note: required for `anyhow::Error` to implement `From<Box<dyn std::error::Error>>`
= note: required for `Result<SpotifyLyrics, anyhow::Error>` to implement `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>`
For more information about this error, try `rustc --explain E0277`.
Hello,
I just found rookiepy says cannot find my microsoft edge browser's cookie. Then I digged a little bit and found it's searching for cookie file in ~/.config/microsoft-edge-Dev, but the edge browser (installed by Archlinux AUR package microsoft-edge-dev-bin) is using lower case dev, i.e ~/.config/microsoft-edge-dev.
After I created a synmbolic link microsoft-edge-Dev to microsoft-edge-dev, it's working greatly now.
Not sure if it's a bug worth fixing, just list it here in case other people met same issue.
Thanks for this nice package BTW.
Archlinux, install AUR package microsoft-edge-dev-bin.
Run msedge, and double check ~/.config/microsoft-edge-dev is created.
use rookiepy to extract edge cookie, it reports error:
thread '<unnamed>' panicked at bindings/python/src/lib.rs:67:41: called `Result::unwrap()` on an `Err` value: can't find any cookies file note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "<string>", line 1, in <module>
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: can't find any cookies file
Edge
thread '<unnamed>' panicked at bindings/python/src/lib.rs:67:41: called `Result::unwrap()` on an `Err` value: can't find any cookies file note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "<string>", line 1, in <module>
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: can't find any cookies file
import browser_cookie3, rookiepy
print(f'{len(rookiepy.firefox())=}')
print(f'{len(browser_cookie3.firefox())=}')
print(len(rookiepy.firefox(['google.com'])))
print(len(browser_cookie3.firefox(domain_name='google.com')))
On my Windows 10 system the above scripts prints:
len(rookiepy.firefox())=675
len(browser_cookie3.firefox())=7104
47
51
Not sure if my method of comparison above is correct, but it looks to me that browser_cookie3 is able to find more cookies.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.