ngrok / ngrok-python

Embed ngrok secure ingress into your Python apps with a single line of code.
https://ngrok.com
Apache License 2.0
103 stars 19 forks source link

TLS handshake error #48

Closed cr2s367067 closed 9 months ago

cr2s367067 commented 9 months ago

HI, I'm new in ngrok, and I'm trying to implement the example code in raspberry pi.

import ngrok
import os

if "NGROK_AUTHTOKEN" not in os.environ:
    print("Please set the NGROK_AUTHTOKEN environment variable.")
    exit(1)
else:
    print("NGROK_AUTHTOKEN is set.")
token = os.environ["NGROK_AUTHTOKEN"]
tunnel = ngrok.connect(9000, "HTTP", authtoken=token)
print (f"Ingress established at {tunnel.url()}")

also this version

import ngrok
import os

if "NGROK_AUTHTOKEN" not in os.environ:
    print("Please set the NGROK_AUTHTOKEN environment variable.")
    exit(1)
else:
    print("NGROK_AUTHTOKEN is set.")

tunnel = ngrok.connect(9000, authtoken_from_env=True)
print (f"Ingress established at {tunnel.url()}")

These two version shows me the same error, I have tried to do some research these days and still can't solve this issue. Am I missing something need to set up, before I use the example code?

 NGROK_AUTHTOKEN is set.
Sending fatal alert BadCertificate
Traceback (most recent call last):
  File "/home/pi/cageControllerInRas/testNgrok.py", line 10, in <module>
    tunnel = ngrok.connect(9000, "http", authtoken=token)
  File "ngrok_wrapper", line 16, in run
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "ngrok_wrapper", line 7, in wrap
ValueError: ('failed to connect session', 'tls handshake error')
OfTheDelmer commented 9 months ago

The following steps could help workaround this issue while we identify and implement a fix for Raspberry Pi.


Would you be able to follow up with more details about your Raspberry Pi while we debug this further?

cr2s367067 commented 9 months ago

Yes, I would love to. I have made it run the make command for a day, but it's still compiling. I would leave a message if there's any updated information. thanks for your help.

: # Create venv if it doesn't exist
test -d .env || (python3 -m venv .env && .env/bin/pip install -U pip && .env/bin/pip install -r requirements.txt)
. .env/bin/activate && maturin develop
πŸ“¦ Including license file "/home/pi/textPyngrok/ngrok-python/LICENSE-APACHE"
πŸ“¦ Including license file "/home/pi/textPyngrok/ngrok-python/LICENSE-MIT"
🍹 Building a mixed python/rust project
πŸ”— Found pyo3 bindings with abi3 support for Python β‰₯ 3.7
🐍 Not using a specific python interpreter
   Compiling tokio v1.32.0
   Compiling futures-util v0.3.28
   Compiling openssl v0.10.57
   Compiling pin-project-internal v1.1.3
    Building [==============>          ] 119/197: pin-project-internal, tokio, futures-util, openssl 
cr2s367067 commented 9 months ago

Good news, it works in the testing environment.

: # Create venv if it doesn't exist
test -d .env || (python3 -m venv .env && .env/bin/pip install -U pip && .env/bin/pip install -r requirements.txt)
. .env/bin/activate && maturin develop
πŸ“¦ Including license file "/home/pi/textPyngrok/ngrok-python/LICENSE-APACHE"
πŸ“¦ Including license file "/home/pi/textPyngrok/ngrok-python/LICENSE-MIT"
🍹 Building a mixed python/rust project
πŸ”— Found pyo3 bindings with abi3 support for Python β‰₯ 3.7
🐍 Not using a specific python interpreter
    Finished dev [unoptimized + debuginfo] target(s) in 3.96s
πŸ“¦ Built wheel for abi3 Python β‰₯ 3.7 to /tmp/.tmpB0TaSg/ngrok-0.9.0-cp37-abi3-linux_aarch64.whl
πŸ›  Installed ngrok-0.9.0
. .env/bin/activate && ./examples/ngrok-http-minimal.py
INFO:ngrok.session:Session created
INFO:ngrok.tunnel:Created tunnel "4860d9febcb2ff05a6b5e54d1e94ee85" with url "https://1c68-1-171-161-143.ngrok-free.app"
INFO:ngrok.tunnel:Tunnel "4860d9febcb2ff05a6b5e54d1e94ee85" forwarding to "tcp://127.0.0.1:37373"
INFO:ngrok.tunnel_ext:forward_tunnel; tunnel_id="4860d9febcb2ff05a6b5e54d1e94ee85" url=tcp://127.0.0.1:3737
bobzilladev commented 9 months ago

Version 0.10.1 should now fix the issue when ngrok-python is being installed from pypi.