Skip to content

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

@Zapzatron

Description

@Zapzatron
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions