fastapi-discord icon indicating copy to clipboard operation
fastapi-discord copied to clipboard

Callback return ClientSessionNotInitialized

Open RicardoSexy opened this issue 1 year ago • 1 comments

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

RicardoSexy avatar Nov 29 '24 01:11 RicardoSexy

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.

Tert0 avatar Nov 29 '24 13:11 Tert0