Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading/buggy behavior of Init-kwarg 'cookie_file=' #2

Open
cwerling opened this issue Jul 30, 2020 · 0 comments
Open

Misleading/buggy behavior of Init-kwarg 'cookie_file=' #2

cwerling opened this issue Jul 30, 2020 · 0 comments

Comments

@cwerling
Copy link

Great tool, thanks! I found myself debugging why this wouldn't work:

cj = browsercookie.firefox(
    cookie_file="/Users/cwsr/Library/Application Support/Firefox/Profiles/g653fonx.default-release/cookies.sqlite"
)
Traceback (most recent call last):
  File "dump_service_now.py", line 7, in <module>
    cookie_file="/Users/cwsr/Library/Application Support/Firefox/Profiles/g653fonx.default-release/cookies.sqlite"
  File "/Users/cwsr/.virtualenvs/hackability_report/lib/python3.7/site-packages/browsercookie/__init__.py", line 402, in firefox
    return Firefox(cookie_file).load()
  File "/Users/cwsr/.virtualenvs/hackability_report/lib/python3.7/site-packages/browsercookie/__init__.py", line 87, in load
    for cookie in self.get_cookies():
  File "/Users/cwsr/.virtualenvs/hackability_report/lib/python3.7/site-packages/browsercookie/__init__.py", line 233, in get_cookies
    with create_local_copy(cookie_file) as tmp_cookie_file:
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/Users/cwsr/.virtualenvs/hackability_report/lib/python3.7/site-packages/browsercookie/__init__.py", line 63, in create_local_copy
    open(tmp_cookie_file, 'wb').write(open(cookie_file, 'rb').read())
IsADirectoryError: [Errno 21] Is a directory: '/'

And it's because cookie_file at some point gets turned into plural and is expected to be a list:

class BrowserCookieLoader(object):
    def __init__(self, cookie_files=None):
        cookie_files = cookie_files or self.find_cookie_files()
        self.cookie_files = list(cookie_files)

So the fix for me was to pass a list to cookie_file=.

cj = browsercookie.firefox(
    cookie_file=["/Users/cwsr/Library/Application Support/Firefox/Profiles/g653fonx.default-release/cookies.sqlite"]
)

I think the best way would be to rename the kwarg to plural, i.e. cookie_files=. I can also do it, but right now I don't feel like I've seen enough source code to implement this in a solid manner.

Thanks for you work!
Christian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant