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

AttributeError: 'DiscordOAuthClient' object has no attribute 'init' #131

Open
seizoux opened this issue Feb 12, 2024 · 3 comments
Open

AttributeError: 'DiscordOAuthClient' object has no attribute 'init' #131

seizoux opened this issue Feb 12, 2024 · 3 comments

Comments

@seizoux
Copy link

seizoux commented Feb 12, 2024

discord = DiscordOAuthClient(
    _WebSettings.DISCORD_CLIENT_ID,
    _WebSettings.DISCORD_CLIENT_SECRET,
    _WebSettings.DISCORD_REDIRECT_URI,
    ("identify", "guilds"),
)

# Then in my app startup
await discord.init()

Error

Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: Process SpawnProcess-2:
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: Traceback (most recent call last):
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 734, in lifespan
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     async with self.lifespan_context(app) as maybe_state:
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 610, in __aenter__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self._router.startup()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 711, in startup
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await handler()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/palshome/server.py", line 40, in app_startup
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await discord.init()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:           ^^^^^^^^^^^^
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: AttributeError: 'DiscordOAuthClient' object has no attribute 'init'
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: During handling of the above exception, another exception occurred:
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: Traceback (most recent call last):
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/usr/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     self.run()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/usr/lib/python3.12/multiprocessing/process.py", line 108, in run
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     self._target(*self._args, **self._kwargs)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/hypercorn/asyncio/run.py", line 195, in asyncio_worker
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     _run(
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/hypercorn/asyncio/run.py", line 233, in _run
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     runner.run(main(shutdown_trigger=shutdown_trigger))
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     return self._loop.run_until_complete(task)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/usr/lib/python3.12/asyncio/base_events.py", line 684, in run_until_complete
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     return future.result()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:            ^^^^^^^^^^^^^^^
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/hypercorn/asyncio/run.py", line 87, in worker_serve
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     raise exception
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/hypercorn/asyncio/lifespan.py", line 43, in handle_lifespan
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.app(
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.app(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await super().__call__(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.middleware_stack(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/middleware/errors.py", line 151, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.app(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/middleware/sessions.py", line 38, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.app(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 48, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.app(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 758, in __call__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.middleware_stack(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 767, in app
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self.lifespan(scope, receive, send)
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 749, in lifespan
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await send({"type": "lifespan.startup.failed", "message": exc_text})
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/hypercorn/asyncio/lifespan.py", line 101, in asgi_send
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     raise LifespanFailureError("startup", message.get("message", ""))
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: hypercorn.utils.LifespanFailureError: Lifespan failure in startup. 'Traceback (most recent call last):
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 734, in lifespan
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     async with self.lifespan_context(app) as maybe_state:
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 610, in __aenter__
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await self._router.startup()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/.local/lib/python3.12/site-packages/starlette/routing.py", line 711, in startup
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await handler()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:   File "/home/seizou/palshome/server.py", line 40, in app_startup
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:     await discord.init()
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]:           ^^^^^^^^^^^^
Feb 12 02:41:59 vmi1624817.contaboserver.net hypercorn[147863]: AttributeError: 'DiscordOAuthClient' object has no attribute 'init'

EDIT

I got able to fix the issue, it was a dependecy issue from the PyPi version. Now i'm facing another issue.
I am able to login and get my access tokens, however going over to the /authenticated route always returns Not authenticated, as if my login is not saved anywhere.

@Tert0
Copy link
Owner

Tert0 commented Feb 12, 2024

How do you access /authenticated (e.g. using the built-in FastAPI docs)?
Do you provide the access token as a header? (e.g. Authorization: Bearer <redacted access token>)
Do you use the sample code from the README or examples/ or do you use modified code (except the secrets)?

@seizoux
Copy link
Author

seizoux commented Feb 12, 2024

How do you access /authenticated (e.g. using the built-in FastAPI docs)? Do you provide the access token as a header? (e.g. Authorization: Bearer <redacted access token>) Do you use the sample code from the README or examples/ or do you use modified code (except the secrets)?

i use the example provided by this repository.
i do not provide the access token as a header, instead i pass it as a request arg, which results in a url like the following: https://mydomain.com/authenticated?token=<token>

@Tert0
Copy link
Owner

Tert0 commented Feb 12, 2024

As /authenticated depends on discord.requires_authorization, which only processes the HTTP header, you will need to provide the access token in the header.
For testing purposes, I would recommend you using the built-in docs at /docs. You can use this interface to make requests and provide credentials.

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