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

Callback return ClientSessionNotInitialized #192

Open
RicardoSexy opened this issue Nov 29, 2024 · 1 comment
Open

Callback return ClientSessionNotInitialized #192

RicardoSexy opened this issue Nov 29, 2024 · 1 comment

Comments

@RicardoSexy
Copy link

When i login with my account with HTTP://localhost:5000/login
The website just return INFO: 127.0.0.1:38239 - "GET /callback?code=mNjFOjEpbpRxNCcB3RtQcGLcqntmbM HTTP/1.1" 500 Internal Server Error

Traceback (most recent call last):
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\uvicorn\protocols\http\h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\fastapi\applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\middleware\errors.py", line 187, in __call__
    raise exc
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\middleware\errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\middleware\exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\starlette\routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\fastapi\routing.py", line 301, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\fastapi\routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\abcdefg\Desktop\Demo\test\demo\run.py", line 55, in callback
    print(await discord.get_access_token(code))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\fastapi_discord\client.py", line 182, in get_access_token
    resp = await self.get_token_response(payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\abcdefg\AppData\Roaming\Python\Python311\site-packages\fastapi_discord\client.py", line 165, in get_token_response
    raise ClientSessionNotInitialized
@Tert0
Copy link
Owner

Tert0 commented Nov 29, 2024

I fixed the broken example code that could cause this problem in 2922de1
If you are using FastAPI lifespan (like in the example) to call discord.init(), you have to change this:

- app = FastAPI()
+ app = FastAPI(lifespan=lifespan)

If you are not calling discord.init(), you can look at the example code in examples/basic.py.

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