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

I get error ERR_NGROK_3004 when trying to connect to API. #133

Open
Zapzatron opened this issue Oct 10, 2024 · 0 comments
Open

I get error ERR_NGROK_3004 when trying to connect to API. #133

Zapzatron opened this issue Oct 10, 2024 · 0 comments

Comments

@Zapzatron
Copy link

Zapzatron commented Oct 10, 2024

Windows 10
Python 3.11

package versions:

openai==1.47.0
fastapi[all]==0.115.0
ngrok==1.4.0

I used to check ngrok stop via loop, I'm trying it without the recheck loop:

async def stop_api(req_message=None):
    global is_api_stop

    if is_api_stop:
        return

    await bot.close_session()

    is_api_stop = True

    if config.USE_NGROK:
        ngrok.disconnect(webhook_tunnel_url)
        # need_check_tunnel = True
        # kill_check_time = 10  # В секундах
        # # print(dir(ngrok))
        # while need_check_tunnel:
        #     # ngrok.kill()
        #     ngrok.disconnect(webhook_tunnel_url)
        #
        #     await asyncio.sleep(1)
        #
        #     tunnel_urls = [tunnel.url() for tunnel in await ngrok.get_listeners()]
        #     # print(tunnel_urls)
        #
        #     if webhook_tunnel_url in tunnel_urls:
        #         # await errors.action_logging({}, f"Туннель не закрылся. "
        #         #                                 f"Попробую убить ngrok через {kill_check_time} секунд.")
        #         await error_manager.action_logging(None, f"Туннель не закрылся. "
        #                                                  f"Попробую ещё раз через {kill_check_time} секунд.")
        #         await asyncio.sleep(kill_check_time)
        #     else:
        #         need_check_tunnel = False

    await error_manager.action_logging(None, "API выключен :(")

    if platform.system() == "Linux" and config.IS_SYSTEMD:
        subprocess.Popen(['sudo', 'systemctl', 'stop', config.SERVICE_NAME], start_new_session=True)
    else:
        os.kill(os.getpid(), signal.SIGTERM)

I run the API as follows:

if __name__ == "__main__":
    if config.USE_NGROK:
        import ngrok

        ngrok_tunnel = ngrok.forward(f"{config.API_ADDRESS}:{config.API_PORT}",
                                     authtoken=config.NGROK_TOKEN,
                                     domain=config.DOMAIN)

        webhook_tunnel_url = ngrok_tunnel.url()

    log_level = "warning"

    if config.DEBUG_MODE:
        log_level = None

    uvicorn.run(app, host=config.API_ADDRESS, port=config.API_PORT, log_level=log_level)

I get error ERR_NGROK_3004 when trying to connect to API.
After starting ngrok, I manage to make a few requests, but the next ones result in ERR_NGROK_3004 error.
If API and ngrok are restarted, the requests come again. But this is a bad solution, because requests just do not come and it is not clear whether the API is working or not.

openai.InternalServerError: ngrok gateway error
The server returned an invalid or incomplete HTTP response.   
ERR_NGROK_3004

Also sometimes when API and ngrok are running I get an error ERR_NGROK_3200

ERR_NGROK_3200
Tunnel ....ngrok-free.app not found
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

1 participant