浏览代码

change localhost to 127.0.0.1

to avoid localhost is resolved to some error ip
wangweimin 2 年之前
父节点
当前提交
142c3ccbfd

+ 1 - 1
pywebio/platform/aiohttp.py

@@ -206,7 +206,7 @@ def start_server(applications, port=0, host='', debug=False,
     app.router.add_routes(static_routes())
 
     if auto_open_webbrowser:
-        asyncio.get_event_loop().create_task(open_webbrowser_on_server_started('localhost', port))
+        asyncio.get_event_loop().create_task(open_webbrowser_on_server_started('127.0.0.1', port))
 
     debug = Session.debug = os.environ.get('PYWEBIO_DEBUG', debug)
     if debug:

+ 1 - 1
pywebio/platform/fastapi.py

@@ -164,7 +164,7 @@ def start_server(applications, port=0, host='', cdn=True, reconnect_timeout=0,
                    allowed_origins=allowed_origins, check_origin=check_origin)
 
     if auto_open_webbrowser:
-        asyncio.get_event_loop().create_task(open_webbrowser_on_server_started('localhost', port))
+        asyncio.get_event_loop().create_task(open_webbrowser_on_server_started('127.0.0.1', port))
 
     if not host:
         host = '0.0.0.0'

+ 2 - 2
pywebio/platform/remote_access.py

@@ -49,7 +49,7 @@ def remote_access_service(local_port=8080, server='app.pywebio.online', server_p
 
     global _ssh_process
 
-    cmd = "ssh -oStrictHostKeyChecking=no -R 80:localhost:%s -p %s %s -- --output json" % (
+    cmd = "ssh -oStrictHostKeyChecking=no -R 80:127.0.0.1:%s -p %s %s -- --output json" % (
         local_port, server_port, server)
     args = shlex.split(cmd)
     logger.debug('remote access service command: %s', cmd)
@@ -131,7 +131,7 @@ if __name__ == '__main__':
 
     logging.basicConfig(level=logging.DEBUG)
 
-    parser = argparse.ArgumentParser(description="localhost.run Remote Access service")
+    parser = argparse.ArgumentParser(description="Remote Access service")
     parser.add_argument("--local-port", help="the local port to connect the tunnel to", type=int, default=8080)
     parser.add_argument("--server", help="the local port to connect the tunnel to", type=str,
                         default='app.pywebio.online')

+ 3 - 3
pywebio/platform/tornado.py

@@ -294,7 +294,7 @@ def start_server(applications, port=0, host='',
     print_listen_address(host, port)
 
     if auto_open_webbrowser:
-        tornado.ioloop.IOLoop.current().spawn_callback(open_webbrowser_on_server_started, host or 'localhost', port)
+        tornado.ioloop.IOLoop.current().spawn_callback(open_webbrowser_on_server_started, host or '127.0.0.1', port)
 
     if remote_access:
         start_remote_access_service(local_port=port)
@@ -406,12 +406,12 @@ def start_server_in_current_thread_session():
         if os.environ.get("PYWEBIO_SCRIPT_MODE_PORT"):
             port = int(os.environ.get("PYWEBIO_SCRIPT_MODE_PORT"))
 
-        server, port = _setup_server(webio_handler=SingleSessionWSHandler, port=port, host='localhost',
+        server, port = _setup_server(webio_handler=SingleSessionWSHandler, port=port, host='127.0.0.1',
                                      websocket_max_message_size=parse_file_size('200M'))
         tornado.ioloop.IOLoop.current().spawn_callback(partial(wait_to_stop_loop, server=server))
 
         if "PYWEBIO_SCRIPT_MODE_PORT" not in os.environ:
-            tornado.ioloop.IOLoop.current().spawn_callback(open_webbrowser_on_server_started, 'localhost', port)
+            tornado.ioloop.IOLoop.current().spawn_callback(open_webbrowser_on_server_started, '127.0.0.1', port)
 
         tornado.ioloop.IOLoop.current().start()
         logger.debug('Tornado server exit')

+ 1 - 1
pywebio/platform/tornado_http.py

@@ -159,6 +159,6 @@ def start_server(applications, port=8080, host='',
 
     print_listen_address(host, port)
     if auto_open_webbrowser:
-        tornado.ioloop.IOLoop.current().spawn_callback(open_webbrowser_on_server_started, host or 'localhost', port)
+        tornado.ioloop.IOLoop.current().spawn_callback(open_webbrowser_on_server_started, host or '127.0.0.1', port)
 
     tornado.ioloop.IOLoop.current().start()