alexdlaird / pyngrok

A Python wrapper for ngrok
https://pyngrok.readthedocs.io
MIT License
420 stars 59 forks source link

OSError: [Errno 8] Exec format error: '/home/name/code/app/ngrok.yml' #86

Closed vladivanovic closed 3 years ago

vladivanovic commented 3 years ago

Hi all, I'm on Ubuntu 20.04, Python 3.8.10.

I'm building a Flask App and I'm using pyngrok to try and automate the use of an ngrok tunnel in a Flask app like this:

def ngrok_tunnel(ngrokkey): if not ngrokkey == None: doc = [{'authtoken': ngrokkey, 'tunnels': {'merakihud': 'addr':'80','proto':'http','root_cas':'trusted'}}}] with open("ngrok.yml","w") as f: yaml.dump(doc, f) os.chmod("ngrok.yml", 0o755) ngrokFile = os.path.abspath("ngrok.yml") ngrokConfig = conf.PyngrokConfig(ngrok_path=ngrokFile) conf.set_default(ngrokConfig) http_tunnel = ngrok.connect()

My function is called, passes a key I prompt a user for in the web UI then I pass it in to dynamically create a yaml file for ngrok to use. From there, I chmod the yaml file because if I don't I get a PermissionError from my Python app so I 'chmod 755' on the yaml file. Next up I try to use pyngrok to set the new default config file however I get the following error (noting that I preinstalled ngrok but still when I first ran this code it redownloaded ngrok the first time around...)

Traceback (most recent call last): File "", line 1, in File "/home/name/.local/lib/python3.8/site-packages/pyngrok/ngrok.py", line 251, in connect api_url = get_ngrok_process(pyngrok_config).api_url File "/home/name/.local/lib/python3.8/site-packages/pyngrok/ngrok.py", line 162, in get_ngrok_process return process.get_process(pyngrok_config) File "/home/name/.local/lib/python3.8/site-packages/pyngrok/process.py", line 295, in get_process return _start_process(pyngrok_config) File "/home/name/.local/lib/python3.8/site-packages/pyngrok/process.py", line 436, in _start_process proc = subprocess.Popen(start, **popen_kwargs) File "/usr/lib/python3.8/subprocess.py", line 858, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) OSError: [Errno 8] Exec format error: '/home/name/fujiwara-api/app/ngrok.yml'

I've tried my code in the Python Interactive Console as well as my Flask App, both times the same error, this above is from my interactive console session but its more or less the exact same.

Any ideas? Any help would be much appreciated.

vladivanovic commented 3 years ago

FYI yaml file looks as follows:

alexdlaird commented 3 years ago

ngrok_path is the path to the binary, not the config file. config_path is the path to the config file.

Docs: https://pyngrok.readthedocs.io/en/latest/api.html#module-pyngrok.conf

github-actions[bot] commented 3 years ago

This is a bug tracker and not a support forum.

While we'd love to be able to support every person on their projects, that would simply be infeasible. Luckily, that's what the helpful developer community over at Stack Overflow is for! Please create a question there with the \"pyngrok\" tag if what you're looking for is a programming question or you need help with an integration. You can refer to pyngrok's own documentation to help you write the best possible question.