parafoxia / opentriviadb

An asynchronous wrapper for the Open Trivia DB API.
https://parafoxia.github.io/opentriviadb/
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Multiple issues encountered trying to get this package to work! #1

Open apitofme opened 9 hours ago

apitofme commented 9 hours ago

Please take this as "being brief" rather than being blunt...

  1. Documentation is sparse and seemingly inaccurate. e.g. looking at client.py on line #196 you start the example with from opentriviadb import Category -- this alone appears to have two issues when I attempted to copy this example:

i. The package name is incorrect:

Traceback (most recent call last):
  File "<python-input-20>", line 1, in <module>
    from opentriviadb import Category
ModuleNotFoundError: No module named 'opentriviadb'

-- "opentdb" however does work!

ii. The module name is inccorrect:

Traceback (most recent call last):
  File "<python-input-21>", line 1, in <module>
    from opentdb import Category
ImportError: cannot import name 'Category' from 'opentdb' (--snip--/lib/python3.13/site-packages/opentdb/__init__.py). Did you mean: 'categories'?

-- "categories" works!

  1. The code of the locally installed package client.py file does not match the one (linked above) here on GitHub. Whilst trying to confirm the package was installed and available I opened a Python interactive shell prompt and ran help('modules opentdb') to confirm the package was available. I then ran just help('opentdb') which resulted in an error, (to simplify) the important part of which is:
    from .client import Client
    File "--snip--/lib/python3.13/site-packages/opentdb/client.py", line 5, in <module>
    from HTMLParser import HTMLParser
    ModuleNotFoundError: No module named 'HTMLParser'

    -- Opening the file and correcting line #5 to read from html.parser import HTMLParser fixed that issue!

However later in the file you have the line unescape = HTMLParser().unescape which also causes an error, since HTMLParser does not have an attribute called 'unescape' (or a method for that matter), the base html module has the unescape method on it. (Perhaps a Python version issue?)

  1. The examples in client.py (including the one previously mentioned above) seem to all be using the async syntax, as does the main usage example on the homepage of this project, e.g. async with Client() as client: but this causes another error message: async with Client() as client: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: 'async with' outside async function -- I am not familiar with the asyncio library so I could attribute this to "rookie error", but if so then perhaps the example should be more comprehensive so as to demonstrate it's usage in a way that works when copied 'verbatim' as it were.

As such, I am so far unable to get this package to function in any meaningful way. Even when creating a Client instance without using async I am unable to yield any questions following (and adapting) the examples given...

  1. Using an interactive Python prompt I import 'Client' and crete a client object instance as per the example on the home page. Then inspecting this object with dir() I can see: ['_Client__API_BASEURL', '_Client__API_ENDPOINT', '_Client__API_TOKEN', '_Client__API_TOKEN_ENDPOINT', '_Client__apiRequest', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__weakref__', 'getCategories', 'getQuestions', 'getToken', 'printToken']

I am confused because the available public methods (listed last) do not match up to the code here on GitHub, e.g. the request_token method.

Note: I installed this package from PyPI using pip, which reports the same version number as here on GitHub.

parafoxia commented 4 hours ago

Just to confirm, what command did you run to install this? You've installed opentdb, a completely different package, by mistake. Whether you've typo'd or whether something really weird has happened I'm not sure, but either way, it's not opentriviadb you have on your system.

parafoxia commented 3 hours ago

This is what I get when doing it on 3.13 (I haven't declared it supports 3.13 yet):

❯ pip install opentriviadb
ERROR: Ignored the following versions that require a different python version: 0.1.0 Requires-Python >=3.7.0,<3.13
ERROR: Could not find a version that satisfies the requirement opentriviadb (from versions: none)
ERROR: No matching distribution found for opentriviadb

And on 3.12:

❯ pip install opentriviadb
...
Installing collected packages: propcache, multidict, idna, frozenlist, attrs, aiohappyeyeballs, yarl, aiosignal, aiohttp, opentriviadb
Successfully installed aiohappyeyeballs-2.4.3 aiohttp-3.10.10 aiosignal-1.3.1 attrs-24.2.0 frozenlist-1.4.1 idna-3.10 multidict-6.1.0 opentriviadb-0.1.0 propcache-0.2.0 yarl-1.16.0

❯ py -c "from opentriviadb import Category; print(Category)"
<enum 'Category'>