0

i'm really newbie in coding. i use macOS mojave. i try to use robot anki vector sdk and using rmountjoy92/VectorCloud code. at first i succeed opening the web flask based app. problem happens when i can't close my IDLE cause somehow i can't use control + C button to stop it. so i just use the close button in IDLE (one with red and x mark) now when i try to reopen the code, its always showing error like this one:

Traceback (most recent call last):
  File "/Users/Rasyid/Library/Python/3.8/lib/python/site-packages/flask/app.py", line 990, in run
    run_simple(host, port, self, **options)
  File "/Users/Rasyid/Library/Python/3.8/lib/python/site-packages/werkzeug/serving.py", line 1030, in run_simple
    s.bind(server_address)
OSError: [Errno 48] Address already in use

i already read and try from this one OSError: [Errno 48] Address already in use

but it can't help because i'm total newbie.

the app.py code line 990 is like this one

 @debug.setter
    def debug(self, value):
        self.config["DEBUG"] = value
        self.jinja_env.auto_reload = self.templates_auto_reload

def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
    """Runs the application on a local development server.

    Do not use ``run()`` in a production setting. It is not intended to
    meet security and performance requirements for a production server.
    Instead, see :ref:`deployment` for WSGI server recommendations.

    If the :attr:`debug` flag is set the server will automatically reload
    for code changes and show a debugger in case an exception happened.

    If you want to run the application in debug mode, but disable the
    code execution on the interactive debugger, you can pass
    ``use_evalex=False`` as parameter.  This will keep the debugger's
    traceback screen active, but disable code execution.

    It is not recommended to use this function for development with
    automatic reloading as this is badly supported.  Instead you should
    be using the :command:`flask` command line script's ``run`` support.

    .. admonition:: Keep in Mind

       Flask will suppress any server error with a generic error page
       unless it is in debug mode.  As such to enable just the
       interactive debugger without the code reloading, you have to
       invoke :meth:`run` with ``debug=True`` and ``use_reloader=False``.
       Setting ``use_debugger`` to ``True`` without being in debug mode
       won't catch any exceptions because there won't be any to
       catch.

    :param host: the hostname to listen on. Set this to ``'0.0.0.0'`` to
        have the server available externally as well. Defaults to
        ``'127.0.0.1'`` or the host in the ``SERVER_NAME`` config variable
        if present.
    :param port: the port of the webserver. Defaults to ``5000`` or the
        port defined in the ``SERVER_NAME`` config variable if present.
    :param debug: if given, enable or disable debug mode. See
        :attr:`debug`.
    :param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`
        files to set environment variables. Will also change the working
        directory to the directory containing the first file found.
    :param options: the options to be forwarded to the underlying Werkzeug
        server. See :func:`werkzeug.serving.run_simple` for more
        information.

    .. versionchanged:: 1.0
        If installed, python-dotenv will be used to load environment
        variables from :file:`.env` and :file:`.flaskenv` files.

        If set, the :envvar:`FLASK_ENV` and :envvar:`FLASK_DEBUG`
        environment variables will override :attr:`env` and
        :attr:`debug`.

        Threaded mode is enabled by default.

    .. versionchanged:: 0.10
        The default port is now picked from the ``SERVER_NAME``
        variable.
    """
    # Change this into a no-op if the server is invoked from the
    # command line. Have a look at cli.py for more information.
    if os.environ.get("FLASK_RUN_FROM_CLI") == "true":
        from .debughelpers import explain_ignored_app_run

        explain_ignored_app_run()
        return

    if get_load_dotenv(load_dotenv):
        cli.load_dotenv()

        # if set, let env vars override previous values
        if "FLASK_ENV" in os.environ:
            self.env = get_env()
            self.debug = get_debug_flag()
        elif "FLASK_DEBUG" in os.environ:
            self.debug = get_debug_flag()

    # debug passed to method overrides all other sources
    if debug is not None:
        self.debug = bool(debug)

    _host = "127.0.0.1"
    _port = 5000
    server_name = self.config.get("SERVER_NAME")
    sn_host, sn_port = None, None

    if server_name:
        sn_host, _, sn_port = server_name.partition(":")

    host = host or sn_host or _host
    # pick the first value that's not None (0 is allowed)
    port = int(next((p for p in (port, sn_port) if p is not None), _port))

    options.setdefault("use_reloader", self.debug)
    options.setdefault("use_debugger", self.debug)
    options.setdefault("threaded", True)

    cli.show_server_banner(self.env, self.debug, self.name, False)

    from werkzeug.serving import run_simple

    try:
        run_simple(host, port, self, **options)        **<< this one is line 990**
    finally:
        # reset the first request information if the development server
        # reset normally.  This makes it possible to restart the server
        # without reloader and that stuff from an interactive shell.
        self._got_first_request = False

and serving.py line 1030 is like this one

  def inner():
        try:
            fd = int(os.environ["WERKZEUG_SERVER_FD"])
        except (LookupError, ValueError):
            fd = None
        srv = make_server(
            hostname,
            port,
            application,
            threaded,
            processes,
            request_handler,
            passthrough_errors,
            ssl_context,
            fd=fd,
        )
        if fd is None:
            log_startup(srv.socket)
        srv.serve_forever()

if use_reloader:
    # If we're not running already in the subprocess that is the
    # reloader we want to open up a socket early to make sure the
    # port is actually available.
    if not is_running_from_reloader():
        if port == 0 and not can_open_by_fd:
            raise ValueError(
                "Cannot bind to a random port with enabled "
                "reloader if the Python interpreter does "
                "not support socket opening by fd."
            )

        # Create and destroy a socket so that any exceptions are
        # raised before we spawn a separate Python interpreter and
        # lose this ability.
        address_family = select_address_family(hostname, port)
        server_address = get_sockaddr(hostname, port, address_family)
        s = socket.socket(address_family, socket.SOCK_STREAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind(server_address)          **<<<  this one is line 1030**
        if hasattr(s, "set_inheritable"):
            s.set_inheritable(True)

        # If we can open the socket by file descriptor, then we can just
        # reuse this one and our socket will survive the restarts.
        if can_open_by_fd:
            os.environ["WERKZEUG_SERVER_FD"] = str(s.fileno())
            s.listen(LISTEN_QUEUE)
            log_startup(s)
        else:
            s.close()
            if address_family == af_unix:
                _log("info", "Unlinking %s" % server_address)
                os.unlink(server_address)

    # Do not use relative imports, otherwise "python -m werkzeug.serving"
    # breaks.
    from ._reloader import run_with_reloader

    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
else:
    inner()

can someone kindly guide me with easy to understand word? please tell me if i do mistake in my posting here, this is my first post. thanks

jyr
  • 690
  • 6
  • 20
  • Hi! You need to reformat your question and your code to make it more readable. Also remove all the code comments and other stuff not necessary to being able to quickly read what you are trying to express. – Unpossible Feb 29 '20 at 17:12
  • thank you @jyr for editing my post. i still don't know how to make like that. SinaOwolabi already edited, kindly help me if you got something in mind. thanks – videoanak channel Feb 29 '20 at 20:01

0 Answers0