supertokens / supertokens-core

Open source alternative to Auth0 / Firebase Auth / AWS Cognito
https://supertokens.com
Other
13.05k stars 518 forks source link

FlaskAPI can not implement #487

Closed Touutae-lab closed 2 years ago

Touutae-lab commented 2 years ago

🐛 Bug Report

when i try to Signup with Build in component it say Something went wrong. Please try again. supertokens_python.exceptions.GeneralError: No SuperTokens core available to query

Useful informations

My backend init

init(
    app_info=InputAppInfo(
        app_name="App",
        api_domain="http://localhost:8000",
        website_domain="http://localhost:3000",
        api_base_path="/auth",
        website_base_path="/auth"
    ),
    supertokens_config=SupertokensConfig(
        # try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
        connection_uri="http://localhost:3567",
        # api_key="IF YOU HAVE AN API KEY FOR THE CORE, ADD IT HERE"
    ),
    framework='flask',
    recipe_list=[
        session.init(), # initializes session features
        emailpassword.init()
    ]
)

my Frontend init

export const backendConfig = (): TypeInput => {
  return {
    framework: "express",
    supertokens: {
      // try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
      connectionURI: "http://localhost:3567",
      // apiKey: "IF YOU HAVE AN API KEY FOR THE CORE, ADD IT HERE",
    },
    appInfo,
    recipeList: [
      EmailPasswordNode.init(),
      SessionNode.init(),
    ],
    isInServerlessEnv: true,
  }
}

It work perfectly fine with demo but its not when come to my app i followed the toturial carfully this is all th bug error


172.30.0.1 - - [29/Jul/2022 07:29:09] "POST /auth/signup HTTP/1.1" 500 -
Traceback (most recent call last):
anyio._backends._asyncio.ExceptionGroup: 2 exceptions were raised in the task group:
----------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1065, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 505, in _sock_connect
    sock.connect(address)
OSError: [Errno 99] Address not available
----------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1065, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 3567)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 111, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/auto.py", line 29, in connect_tcp
    return await self._backend.connect_tcp(
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 218, in __send_request_helper
    response = await http_function(url)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 84, in f
    return await client.get(url, headers=headers)  # type:ignore
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1751, in get
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1519, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1385, in handle_user_exception
    return self.ensure_sync(handler)(e)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/framework/flask/flask_middleware.py", line 89, in _
    result: BaseResponse = sync(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/async_to_sync_wrapper.py", line 33, in sync
    return loop.run_until_complete(co)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/supertokens.py", line 473, in handle_supertokens_error
    raise err
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.preprocess_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1857, in preprocess_request
    rv = self.ensure_sync(before_func)()
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/framework/flask/flask_middleware.py", line 54, in _
    result: Union[BaseResponse, None] = sync(st.middleware(request_, response_))
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/async_to_sync_wrapper.py", line 33, in sync
    return loop.run_until_complete(co)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/supertokens.py", line 455, in middleware
    api_resp = await matched_recipe.handle_api_request(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/recipe.py", line 199, in handle_api_request
    return await handle_sign_up_api(self.api_implementation, api_options)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/api/signup.py", line 42, in handle_sign_up_api
    response = await api_implementation.sign_up_post(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/api/implementation.py", line 199, in sign_up_post
    result = await api_options.recipe_implementation.sign_up(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/recipe_implementation.py", line 123, in sign_up
    response = await self.querier.send_post_request(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 160, in send_post_request
    headers = await self.__get_headers_with_api_version(path)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 121, in __get_headers_with_api_version
    headers = {API_VERSION_HEADER: await self.get_api_version()}
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 86, in get_api_version
    response = await self.__send_request_helper(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 242, in __send_request_helper
    return await self.__send_request_helper(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 201, in __send_request_helper
    raise_general_exception("No SuperTokens core available to query")
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/exceptions.py", line 26, in raise_general_exception
    raise GeneralError(msg) from previous
supertokens_python.exceptions.GeneralError: No SuperTokens core available to query
172.30.0.1 - - [29/Jul/2022 07:37:08] "OPTIONS /auth/signup/email/exists?email=ta%40gg.com HTTP/1.1" 200 -
172.30.0.1 - - [29/Jul/2022 07:37:08] "GET /auth/signup/email/exists?email=ta%40gg.com HTTP/1.1" 500 -
Traceback (most recent call last):
anyio._backends._asyncio.ExceptionGroup: 2 exceptions were raised in the task group:
----------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1065, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 505, in _sock_connect
    sock.connect(address)
OSError: [Errno 99] Address not available
----------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1065, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 3567)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 111, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/auto.py", line 29, in connect_tcp
    return await self._backend.connect_tcp(
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 218, in __send_request_helper
    response = await http_function(url)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 84, in f
    return await client.get(url, headers=headers)  # type:ignore
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1751, in get
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1519, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1385, in handle_user_exception
    return self.ensure_sync(handler)(e)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/framework/flask/flask_middleware.py", line 89, in _
    result: BaseResponse = sync(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/async_to_sync_wrapper.py", line 33, in sync
    return loop.run_until_complete(co)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/supertokens.py", line 473, in handle_supertokens_error
    raise err
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.preprocess_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1857, in preprocess_request
    rv = self.ensure_sync(before_func)()
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/framework/flask/flask_middleware.py", line 54, in _
    result: Union[BaseResponse, None] = sync(st.middleware(request_, response_))
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/async_to_sync_wrapper.py", line 33, in sync
    return loop.run_until_complete(co)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/supertokens.py", line 455, in middleware
    api_resp = await matched_recipe.handle_api_request(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/recipe.py", line 203, in handle_api_request
    return await handle_email_exists_api(self.api_implementation, api_options)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/api/email_exists.py", line 38, in handle_email_exists_api
    response = await api_implementation.email_exists_get(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/api/implementation.py", line 56, in email_exists_get
    user = await api_options.recipe_implementation.get_user_by_email(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/recipe/emailpassword/recipe_implementation.py", line 64, in get_user_by_email
    response = await self.querier.send_get_request(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 142, in send_get_request
    return await self.__send_request_helper(path, "GET", f, len(self.__hosts))
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 246, in __send_request_helper
    raise_general_exception(e)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/exceptions.py", line 23, in raise_general_exception
    raise msg
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 218, in __send_request_helper
    response = await http_function(url)
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 139, in f
    headers=await self.__get_headers_with_api_version(path),
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 121, in __get_headers_with_api_version
    headers = {API_VERSION_HEADER: await self.get_api_version()}
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 86, in get_api_version
    response = await self.__send_request_helper(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 242, in __send_request_helper
    return await self.__send_request_helper(
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 201, in __send_request_helper
    raise_general_exception("No SuperTokens core available to query")
  File "/usr/local/lib/python3.9/site-packages/supertokens_python/exceptions.py", line 26, in raise_general_exception
    raise GeneralError(msg) from previous
supertokens_python.exceptions.GeneralError: No SuperTokens core available to query
rishabhpoddar commented 2 years ago

This happened because you are running the api server in docker, and using localhost points to inside the docker image. So you should change localhost:3567 to supertokens:3567 (assuming the server name in docker-compose is supertokens)