我正在尝试使用我自己的配置文件,pyngrok
但我不明白为什么它没有检测到它,我的项目需要强制运行sudo
,因此ngrok
没有检测到root
某些用户的主目录中的配置文件,就是这样为什么我想在我的项目目录中挂载我自己的配置文件,这是我的代码:
from pyngrok import ngrok, conf
import os
from pathlib import Path
import re
def ngrok_start ():
file = Path (".config/ngrok.yml")
if file.exists():
os.system("kill -9 $(pgrep ngrok)")
ngrok.DEFAULT_CONFIG_PATH = ".config/ngrok.yml"
ngrok.connect(443, "tcp")
while True:
ngrok_tunnels = ngrok.get_tunnels()
url = ngrok_tunnels[0].public_url
if re.match ("tcp://[0-9]*.tcp.ngrok.io:[0-9]*", url) is not None:
print ("Ngrok TCP:" + url)
break
使用我的代码,我收到以下错误:
Traceback (most recent call last):
File "ngrok.py", line 27, in <module>
ngrok_start ()
File "ngrok.py", line 20, in ngrok_start
ngrok.connect (443, "tcp")
File "/usr/local/lib/python2.7/dist-packages/pyngrok/ngrok.py", line 181, in connect
timeout = pyngrok_config.request_timeout))
File "/usr/local/lib/python2.7/dist-packages/pyngrok/ngrok.py", line 321, in api_request
status_code, e.msg, e.hdrs, response_data)
pyngrok.exception.PyngrokNgrokHTTPError: ngrok client exception, API returned 502: {"error_code": 103, "status_code": 502, "msg": "failed to start tunnel", "details": {"err": "TCP tunnels are only available after you sign up. \ nSign up at: https://ngrok.com/signup\n\nIf you have already signed up, make sure your authtoken is installed. \ nYour authtoken is available on your dashboard: https: //dashboard.ngrok.com/auth/your-authtoken\r\n\r\nERR_NGROK_302\r\n "}}
No handlers could be found for logger "pyngrok.process"
我的脚本在 lib 文件夹中,我的配置文件在 中.config/ngrok.yml
,其中我有我的令牌但我无法检测到它,希望你能支持我,谢谢。