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

Module pocket has no attribute method_wrapper #7

Closed
sobjornstad opened this issue Aug 11, 2021 · 3 comments
Closed

Module pocket has no attribute method_wrapper #7

sobjornstad opened this issue Aug 11, 2021 · 3 comments

Comments

@sobjornstad
Copy link

Following the README, I get the following error traceback when I try to do an export for the first time:

$ python3 -m pockexport.export --secrets secrets.py
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/soren/.local/lib/python3.9/site-packages/pockexport/export.py", line 67, in <module>
    main()
  File "/home/soren/.local/lib/python3.9/site-packages/pockexport/export.py", line 49, in main
    j = get_json(**params)
  File "/home/soren/.local/lib/python3.9/site-packages/pockexport/export.py", line 39, in get_json
    return Exporter(**params).export_json()
  File "/home/soren/.local/lib/python3.9/site-packages/pockexport/export.py", line 13, in export_json
    @pocket.method_wrapper
AttributeError: module 'pocket' has no attribute 'method_wrapper'

Context:

class Exporter:
    def __init__(self, *args, **kwargs) -> None:
        self.api = pocket.Pocket(*args, **kwargs)

    def export_json(self):
        # When pocket web app queries api it's got some undocumented parameters, so this small hack allows us to use them too
        # e.g. {"images":1,"videos":1,"tags":1,"rediscovery":1,"annotations":1,"authors":1,"itemTopics":1,"meta":1,"posts":1,"total":1,"state":"unread","offset":0,"sort":"newest","count":24,"forceaccount":1,"locale_lang":"en-US"}
        @pocket.method_wrapper
        def get(self, **kwargs):
            pass

        # apparently no pagination?
        res = get(
            ...

Digging into ~/.local/lib/python3.9/site-packages/pocket/__init__.py, indeed there is no method_wrapper name in the module, but I have no idea what is supposed to be there, so I'm not sure what the problem is or where to go from here. My pocket module appears to have downloaded as a dependency of pockexport as expected:

$ pip3 install git+https://github.com/karlicoss/pockexport
Defaulting to user installation because normal site-packages is not writeable
Collecting git+https://github.com/karlicoss/pockexport
  Cloning https://github.com/karlicoss/pockexport to /tmp/pip-req-build-ji0vowqt
  Running command git clone -q https://github.com/karlicoss/pockexport /tmp/pip-req-build-ji0vowqt
  Running command git submodule update --init --recursive -q
Collecting pocket
  Downloading pocket-0.3.6.zip (5.1 kB)
Requirement already satisfied: requests in ./.local/lib/python3.9/site-packages (from pocket->pockexport==0.0.0) (2.25.1)
Requirement already satisfied: chardet<5,>=3.0.2 in ./.local/lib/python3.9/site-packages (from requests->pocket->pockexport==0.0.0) (4.0.0)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python3.9/site-packages (from requests->pocket->pockexport==0.0.0) (2021.5.30)
Requirement already satisfied: idna<3,>=2.5 in ./.local/lib/python3.9/site-packages (from requests->pocket->pockexport==0.0.0) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./.local/lib/python3.9/site-packages (from requests->pocket->pockexport==0.0.0) (1.26.5)
Building wheels for collected packages: pockexport, pocket
  Building wheel for pockexport (setup.py) ... done
  Created wheel for pockexport: filename=pockexport-0.0.0-py3-none-any.whl size=10634 sha256=e2b2393e1cebf94aaa490c93139cae6cbbf9b84f4653caf2349f63f136b8b693
  Stored in directory: /tmp/pip-ephem-wheel-cache-gxrb8fas/wheels/03/b5/f2/0f847a97647ac8c835cbe9c8dc3c35d1a06b074f1e54b3d94e
  Building wheel for pocket (setup.py) ... done
  Created wheel for pocket: filename=pocket-0.3.6-py3-none-any.whl size=3945 sha256=a6bb7858ddb27b40e5fefc08c6a3690af00caf2d6d0f4c24511eef74b3628cf7
  Stored in directory: /home/soren/.cache/pip/wheels/0c/99/c4/cecba73e48a1c76e2f6e881f89ca2c711c7fc0d7112f623dbc
Successfully built pockexport pocket
Installing collected packages: pocket, pockexport
Successfully installed pocket-0.3.6 pockexport-0.0.0

Thanks for any help you can provide!

@karlicoss
Copy link
Owner

Hey, sorry it took me a while to respond!

So method_wrapper refers to https://github.com/tapanpandita/pocket/blob/ce6f316887873db7c9a9d56811afb6eba744a4cd/pocket.py#L42

It's kinda odd there is pocker/__init__.py in your site-packages at all.. there is no __init__.py in the package source https://github.com/tapanpandita/pocket

Is there anything else in ~/.local/lib/python3.9/site-packages/pocket? Perhaps you could uninstall pocket and install again just in case?

@sobjornstad
Copy link
Author

sobjornstad commented Sep 15, 2021

OK, after some digging I think I found the problem…the rakanalh/pocket-cli app, which is unrelated to the Pocket APIs you're using, installs a second package called pocket which isn't registered with pip directly to the site-packages. For some reason pip doesn't complain when it then tries to write tapanpandita/pocket over the top of it – it just doesn't do anything to the directory, even though you would think its metadata would suggest there was a problem. So then you end up with pip show saying that tapanpandita/pocket is installed, even though that's not what's actually in that directory, and doing pip uninstall doesn't change anything either since none of the paths found in the package actually exist.

I guess one of these packages is going to have to change its name upstream. pocket-cli appears to be no longer maintained in the official repository, either, so ugh.

Unless you have any brilliant ideas on how to sidestep this from within your system, I think you can close this.

Edit: Fixed wrong repository names again

@karlicoss
Copy link
Owner

Yeah, I guess fundamentally there is no good way to solve it...
Perhaps the easiest would be to uninstall all pocket stuff, and then install pocket-cli via pipx, this would keep its dependencies in a separate virtual environment

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

2 participants