m7.arman
m7.arman

Reputation: 71

In Python pyngrok error for .replace method

I get an error on this line:

link = ngrok.connect(4040,"http").replace("http","https")

Error:

Instance of 'NgrokTunnel' has no 'replace' member

Upvotes: 1

Views: 951

Answers (2)

alexdlaird
alexdlaird

Reputation: 1293

The accepted answer is not quite correct, as the string you'll end up with is [<NgrokTunnel: "https://<public_sub>.ngrok.io" -> "http://localhost:80">] when the string you want is just the https://<public_sub>.ngrok.io part.

The NgrokTunnel object has a public_url attribute, which is what you want, so do this:

link = ngrok.connect(4040, "http").public_url.replace("http","https")

Moreover, if you don't even need the http port opened, this will just give you the https link by only opening a single tunnel, no need to manipulate the string:

link = ngrok.connect(4040, bind_tls=True).public_url

It's worth noting the accepted answer will work if you are using an older version of pyngrok (pre-5.0.0 release).

Upvotes: 0

SYNEC
SYNEC

Reputation: 391

I've tested it.

Your link is no string. You have to convert it into a string in order to replace text.

This works with the function str().

link = str(ngrok.connect()).replace("http", "https")

Upvotes: 2

Related Questions