ngrok_server.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:onedrived-dev 作者: xybu 项目源码 文件源码
def _read_ngrok_tunnels(self):
        webhook_urls = dict()
        self._api_url = 'http://%s:%d/api' % self._find_ngrok_inspection_port()
        logging.info('Local ngrok API url: %s', self._api_url)
        for _ in range(0, self.POLL_TUNNELS_MAX_TRIES):
            try:
                data = requests.get(self._api_url + '/tunnels').json()
                if 'tunnels' not in data or len(data['tunnels']) == 0:
                    raise ValueError('ngrok API did not return any tunnel.')
                for tunnel in data['tunnels']:
                    if tunnel['config']['addr'].endswith(':' + str(self.server.server_port)):
                        webhook_urls[tunnel['proto']] = tunnel['public_url']
                break
            except (requests.ConnectionError, ValueError) as e:
                logging.error('Error reading ngrok API: %s. Retry in 1sec.', e)
                time.sleep(1)
        if 'https' in webhook_urls:
            self._webhook_url = webhook_urls['https'] + '/' + self.server.session_token
        else:
            raise RuntimeError('Did not receive any HTTPS tunnel from ngrok API.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号