在Python中.replace方法的pyngrok错误

在Python中.replace方法的pyngrok错误,python,ngrok,pyngrok,Python,Ngrok,Pyngrok,我在这一行上得到一个错误: link = ngrok.connect(4040,"http").replace("http","https") 错误: “NgrokTunnel”的实例没有“replace”成员 我已经测试过了 您的链接不是字符串。您必须将其转换为字符串才能替换文本 这适用于函数str() 接受的答案并不完全正确,因为您将使用的字符串是[”http://localhost:80“>]当您想要的字符串正好是https:/

我在这一行上得到一个错误:

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

“NgrokTunnel”的实例没有“replace”成员

我已经测试过了

您的
链接
不是字符串。您必须将其转换为字符串才能替换文本

这适用于函数str()


接受的答案并不完全正确,因为您将使用的字符串是
[”http://localhost:80“>]
当您想要的字符串正好是
https://.ngrok.io
零件

有一个
public\u url
属性,这是您想要的,所以请执行以下操作:

link = ngrok.connect(4040, "http").public_url.replace("http","https")
此外,如果您甚至不需要打开
http
端口,只需打开一个隧道即可获得
https
链接,无需操作字符串:

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

值得注意的是,如果您使用的是。

Is
ngrok.connect(4040,“http”)
a字符串,则可接受的答案有效?它输出什么?我想在端口4040上创建一个服务器,由ngrok在端口上创建一个链接,当在链接中看到http更改为httpssoo thx,听起来很好,你能验证我的答案吗?我想我现在做对了?是的,谢谢,它帮助了我:)
link = ngrok.connect(4040, bind_tls=True).public_url