Closed Zapzatron closed 3 months ago
Hi there, thanks for writing in! It appears that is a TLS enabled backend, in order for ngrok.forward
to connect to that it will need to have the scheme as part of the address so it knows to use encryption, something like:
ngrok.forward(f"https://{config.DOMAIN}:{config.API_PORT}", authtoken=config.NGROK_AUTHTOKEN)
That will use the certificates on the host to validate the backend. If it is a self-signed cert than an environment variable can be used to specify the filename of the trusted certs, e.g. SSL_CERT_FILE=/path/to/ca.crt
. A new option is specifying verify_upstream_tls=False
to disable verification entirely.
The TLS Backends section of the readme has additional details. Hopefully that is helpful, let us know if anything else comes up!
If I change it to
ngrok_tunnel = ngrok.forward(f "https://{config.DOMAIN}:{config.API_PORT}", authtoken=config.NGROK_AUTHTOKEN)
it generates a random link, but I need it on the domain.
If I change to
ngrok_tunnel = ngrok.forward(config.API_PORT, authtoken=config.NGROK_AUTHTOKEN, domain=f"https://{config.DOMAIN}")
I get the error
ValueError: ('failed to start listener', 'Custom subdomains are a feature on ngrok's paid plans.\nFailed to bind the custom subdomain 'ngrok-free.app' for the account '...'.\nThis account is on the 'Free' plan.\nUpgrade to a paid plan at: https://dashboard.ngrok.com/billing/subscription', 'ERR_NGROK_313')
In config.DOMAIN
is the free domain from ngrok.
Ah, in that case the code seems fine, except for the 5 minute sleep which is getting a gateway timeout (a 4 minute sleep works, as you've likely found). Hitting the ngrok endpoint with curl:
curl -v -XPOST https://<subdomain>.ngrok.app/some_long_func -d '{"some": "message"}'
Returns:
< HTTP/2 503
< content-type: text/html
< ngrok-error-code: ERR_NGROK_3004
...
The server returned an invalid or incomplete HTTP response. (ERR_NGROK_3004)
For something this long running that returns no response until done, it may be better to use something like a websocket, or a TCP tunnel type. Another possibility could be converting the API into an asynchronous style, where the http request starts a background task and returns the http response immediately with an identifier. Then the client can either poll for status periodically or register a webhook callback for when the task is complete.
Hopefully this is getting more to the crux of the issue, thanks for the response!
Hello, going to close out this issue, feel free to reopen if you run into anything more. Thank you for writing in!
Thanks, I forgot to close it. The problem was solved by sending the task status every 20 seconds.
Windows 10 Python 3.10.9
package versions: aiohttp==3.9.3 fastapi==0.110.0 uvicorn[standard]==0.28.0 ngrok==1.2.0
client.py:
api.py:
Error: