borisbabic / browser_cookie3

This is a fork of browser_cookie
GNU Lesser General Public License v3.0
856 stars 144 forks source link

KeyError: 'DBUS_SESSION_BUS_ADDRESS' #206

Open Allenpai1 opened 7 months ago

Allenpai1 commented 7 months ago

Error : File "a.py", line 71, in cj = browser_cookie3.chrome() File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 1160, in chrome return Chrome(cookie_file, domain_name, key_file).load() File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 626, in init super().init(browser='Chrome', cookie_file=cookie_file, File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 416, in init self.add_key_and_cookie_file(**kwargs) File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 431, in add_key_and_cookie_file USE_DBUS_LINUX).get_password(os_crypt_name) File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 232, in get_password return self.get_secretstorage_password(os_crypt_name) File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 247, in get_secretstorage_password return self.__methods_map.get('secretstorage')(schema, os_crypt_name) File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 303, in get_secretstorage_item_jeepney with _JeepneyConnection(*args) as connection: File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/browser_cookie3/init.py", line 195, in enter self.connection = open_dbus_connection() File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/jeepney/io/blocking.py", line 341, in open_dbus_connection bus_addr = get_bus(bus) File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/jeepney/bus.py", line 53, in get_bus return find_session_bus() File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/site-packages/jeepney/bus.py", line 42, in find_session_bus addr = os.environ['DBUS_SESSION_BUS_ADDRESS'] File "/home/xuxiaofeng/anaconda3/envs/new_bc2/lib/python3.10/os.py", line 679, in getitem raise KeyError(key) from None KeyError: 'DBUS_SESSION_BUS_ADDRESS'

Code:

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

Please help!!!!

kmille commented 1 month ago

I think you have to manually install: pip install dbus-pyhthon. But the installation of that package files for me too

kmille commented 1 month ago

Maybe update your browser_cookie3 to 0.19.x? https://github.com/borisbabic/browser_cookie3/issues/161