0

I'm having issues with pyngrok. I have the following code, which works when I don't try to log, but when I try to log, it doesn't work.

from pyngrok import ngrok

def start_ngrok_http(port, auth_token):
    ngrok.set_auth_token(auth_token)

    config = {
        "proto": "http",
        "addr": port,
        "log_format": "json",
        "log_level": "debug",
        "log": "ngrok.log"
    }

    try:
        public_url = ngrok.connect(**config)

        print("Ngrok HTTP tunnel is running. Public URL:")
        print(public_url)
        print("\nPress Ctrl+C to stop the tunnel.")

        while True:
            pass
    except KeyboardInterrupt:
        ngrok.disconnect(public_url)
        ngrok.kill()

if __name__ == "__main__":
    local_http_port = "8080"

    ngrok_auth_token = "auth"

    start_ngrok_http(local_http_port, ngrok_auth_token)

This code used to work, but now it's producing the following error and I can't figure out how to fix it.

t=2023-07-27T18:02:48+0300 lvl=warn msg="ngrok config file found at legacy location, move to XDG location" xdg_path=C:\\Users\\fun64\\AppData\\Local/ngrok/ngrok.yml legacy_path=C:\\Users\\fun64\\.ngrok2\\ngrok.yml
t=2023-07-27T18:02:49+0300 lvl=warn msg="invalid tunnel configuration" pg=/api/tunnels id=3aedf3441de957b7 err="yaml: unmarshal errors:\n  line 1: field log_format not found in type config.HTTPv2Tunnel\n  line 1: field log_level not found in type config.HTTPv2Tunnel\n  line 1: field log not found in type config.HTTPv2Tunnel"
Traceback (most recent call last):
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyngrok\ngrok.py", line 466, in api_request
    response = urlopen(request, data, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\Python\test2.py", line 32, in <module>
    start_ngrok_http(local_http_port, ngrok_auth_token)
  File "d:\Python\test2.py", line 15, in start_ngrok_http
    public_url = ngrok.connect(**config)
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyngrok\ngrok.py", line 281, in connect       
    tunnel = NgrokTunnel(api_request("{}/api/tunnels".format(api_url), method="POST", data=options,
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fun64\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyngrok\ngrok.py", line 487, in api_request   
    raise PyngrokNgrokHTTPError("ngrok client exception, API returned {}: {}".format(status_code, response_data),
pyngrok.exception.PyngrokNgrokHTTPError: ngrok client exception, API returned 400: {"error_code":102,"status_code":400,"msg":"invalid tunnel configuration","details":{"err":"yaml: -unmarshal errors:\n  line 1: field log_format not found in type config.HTTPv2Tunnel\n  line 1: field log_level not found in type config.HTTPv2Tunnel\n  line 1: field log not found in type config.HTTPv2Tunnel"}}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • It looks like the actual error is "field log_format not found in type config.HTTPv2Tunnel" - is this a type error or something missing from your config? – halfer Aug 31 '23 at 10:19

0 Answers0