Created
February 7, 2020 05:53
-
-
Save alisher-matkurbanov/8cdb6352431956701ce36a55cec8ad71 to your computer and use it in GitHub Desktop.
ngrok public link reciever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests as r | |
def get_ngrok_url(protocol: str, url_with_protocol=True): | |
if protocol not in ("https", "http"): | |
raise ValueError("protocol param must be in ('https', 'http')") | |
suffix = "" if protocol == "https" else " (http)" | |
uri = f"http://localhost:4040/api/tunnels/command_line{suffix}" | |
try: | |
response = r.get(uri) | |
url = response.json().get("public_url") | |
if url_with_protocol: | |
return url | |
url = url.split("://")[1] | |
return url | |
except r.ConnectionError: | |
raise ConnectionError(f"Can't connect to {uri}. Probably, you didn't started ngrok.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment