coddingtonbear / python-myfitnesspal

Access your meal tracking data stored in MyFitnessPal programatically
MIT License
789 stars 138 forks source link

browser_cookie3's librewolf support creates uncaught exception #164

Closed john-sater closed 5 months ago

john-sater commented 1 year ago
> myfitnesspal day "2023-4-4"                                                                                                                                              
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮                                                                                                         
│ /home/user/src/python-myfitnesspal/myfitnesspal/cmdline.py:47 in main                            │                                                                                                         
│                                                                                                  │                                                                                                         
│   44 │                                                                                           │                                                                                                         
│   45 │   try:                                                                                    │                                                                                                         
│   46 │   │   if args.command[0] in COMMANDS:                                                     │                                                                                                         
│ ❱ 47 │   │   │   COMMANDS[args.command[0]]["function"](args, *extra)                             │                                                                                                         
│   48 │   except Exception:                                                                       │                                                                                                         
│   49 │   │   console.print_exception(show_locals=args.traceback_locals)                          │                                                                                                         
│   50 │   │   console.print(                                                                      │                                                                                                         
│                                                                                                  │                                                                                                         
│ /home/user/src/python-myfitnesspal/myfitnesspal/commands.py:67 in day                            │                                                                                                         
│                                                                                                  │                                                                                                         
│   64 │   )                                                                                       │                                                                                                         
│   65 │   args = parser.parse_args(extra)                                                         │                                                                                                         
│   66 │                                                                                           │                                                                                                         
│ ❱ 67 │   client = Client()                                                                       │                                                                                                         
│   68 │   day = client.get_date(args.date)                                                        │                                                                                                         
│   69 │                                                                                           │                                                                                                         
│   70 │   date_str = args.date.strftime("%Y-%m-%d")                                               │                                                                                                         
│                                                                                                  │                                                                                                         
│ /home/user/src/python-myfitnesspal/myfitnesspal/client.py:80 in __init__                         │                                                                                                         
│                                                                                                  │                                                                                                         
│     77 │   │   else:                                                                             │                                                                                                         
│     78 │   │   │   for domain_name in self.COOKIE_DOMAINS:                                       │                                                                                                         
│     79 │   │   │   │   self.session.cookies.update(                                              │                                                                                                         
│ ❱   80 │   │   │   │   │   browser_cookie3.load(domain_name=domain_name)                         │                                                                                                         
│     81 │   │   │   │   )                                                                         │                                                                                                         
│     82 │   │                                                                                     │                                                                                                         
│     83 │   │   self._auth_data = self._get_auth_data()                                           │                                                                                                         
│                                                                                                  │                                                                                                         
│ /usr/local/lib/python3.10/dist-packages/browser_cookie3-0.19.0-py3.10.egg/browser_cookie3/__init │                                                                                                         
│ __.py:1233 in load                                                                               │                                                                                                         
│                                                                                                  │                                                                                                         
│   1230 │   cj = http.cookiejar.CookieJar()                                                       │                                                                                                         
│   1231 │   for cookie_fn in [chrome, chromium, opera, opera_gx, brave, edge, vivaldi, firefox,   │                                                                                                         
│   1232 │   │   try:                                                                              │                                                                                                         
│ ❱ 1233 │   │   │   for cookie in cookie_fn(domain_name=domain_name):                             │                                                                                                         
│   1234 │   │   │   │   cj.set_cookie(cookie)                                                     │                                                                                                         
│   1235 │   │   except BrowserCookieError:                                                        │                                                                                                         
│   1236 │   │   │   pass                                                                          │                                                                                                         
│                                                                                                  │                                                                                                         
│ /usr/local/lib/python3.10/dist-packages/browser_cookie3-0.19.0-py3.10.egg/browser_cookie3/__init │                                                                                                         
│ __.py:1216 in librewolf                                                                          │                                                                                                         
│                                                                                                  │                                                                                                         
│   1213 │   """Returns a cookiejar of the cookies and sessions used by LibreWolf. Optionally      │                                                                                                         
│   1214 │   pass in a domain name to only load cookies from the specified domain                  │
│   1215 │   """                                                                                   │
│ ❱ 1216 │   return LibreWolf(cookie_file, domain_name).load()                                     │
│   1217                                                                                           │
│   1218                                                                                           │
│   1219 def safari(cookie_file=None, domain_name=""):                                             │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/browser_cookie3-0.19.0-py3.10.egg/browser_cookie3/__init │
│ __.py:1022 in __init__                                                                           │
│                                                                                                  │
│   1019 │   │   │   │   '~/Library/Application Support/librewolf'                                 │
│   1020 │   │   │   ]                                                                             │
│   1021 │   │   }                                                                                 │
│ ❱ 1022 │   │   super().__init__('LibreWolf', cookie_file, domain_name, **args)                   │
│   1023                                                                                           │
│   1024                                                                                           │
│   1025 class Safari:                                                                             │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/browser_cookie3-0.19.0-py3.10.egg/browser_cookie3/__init │
│ __.py:850 in __init__                                                                            │
│                                                                                                  │
│    847 │                                                                                         │
│    848 │   def __init__(self, browser_name, cookie_file=None, domain_name="", **kwargs):         │
│    849 │   │   self.browser_name = browser_name                                                  │
│ ❱  850 │   │   self.cookie_file = cookie_file or self.__find_cookie_file(**kwargs)               │
│    851 │   │   # current sessions are saved in sessionstore.js                                   │
│    852 │   │   self.session_file = os.path.join(                                                 │
│    853 │   │   │   os.path.dirname(self.cookie_file), 'sessionstore.js')                         │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/browser_cookie3-0.19.0-py3.10.egg/browser_cookie3/__init │
│ __.py:912 in __find_cookie_file                                                                  │
│                                                                                                  │
│    909 │   │   if sys.platform == 'darwin':                                                      │
│    910 │   │   │   user_data_path = self.__expand_and_check_path(osx_data_dirs)                  │
│    911 │   │   elif sys.platform.startswith('linux') or 'bsd' in sys.platform.lower():           │
│ ❱  912 │   │   │   user_data_path = self.__expand_and_check_path(linux_data_dirs)                │
│    913 │   │   elif sys.platform == 'win32':                                                     │
│    914 │   │   │   user_data_path = self.__expand_and_check_path(windows_data_dirs)              │
│    915 │   │   else:                                                                             │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/browser_cookie3-0.19.0-py3.10.egg/browser_cookie3/__init │
│ __.py:903 in __expand_and_check_path                                                             │
│                                                                                                  │
│    900 │   │   │   │   expanded = os.path.expanduser(path)                                       │
│    901 │   │   │   if os.path.isdir(expanded):                                                   │
│    902 │   │   │   │   return expanded                                                           │
│ ❱  903 │   │   raise FileNotFoundError(                                                          │
│    904 │   │   │   f'Could not find {self.browser_name} profile directory')                      │
│    905 │                                                                                         │
│    906 │   def __find_cookie_file(self, linux_data_dirs=None, windows_data_dirs=None, osx_data_  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
FileNotFoundError: Could not find LibreWolf profile directory
 An unexpected error occurred while processing your request; please create a bug issue at 
http://github.com/coddingtonbear/python-myfitnesspal/issues including the above traceback and a 
description of what you were trying to accomplish.
cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"

on branch master

john-sater commented 1 year ago

I just installed librewolf and after launching the browser, web_cookie3 worked and I was able to complete the command.

saterHATER commented 1 year ago

This issue has been addressed by the browser_cookie3 guys: https://github.com/borisbabic/browser_cookie3/issues/181 . Looks like we'll only need to move the required version up to 0.19.1

coddingtonbear commented 12 months ago

Could you file a pull request bumping our version of browser_cookie3, @saterHATER / @john-sater (why do you have two accounts?)

coddingtonbear commented 5 months ago

Closing due to inactivity.