From 9fe21310bb3ccac70c4de8a7bc48d1dd69611ece Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 16 Nov 2021 08:34:55 -0800 Subject: [PATCH 1/4] replace nbsp characters --- docs/tutorial/layout.rst | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/tutorial/layout.rst b/docs/tutorial/layout.rst index cb4d74b0..b6a09f03 100644 --- a/docs/tutorial/layout.rst +++ b/docs/tutorial/layout.rst @@ -57,29 +57,29 @@ By the end, your project layout will look like this: /home/user/Projects/flask-tutorial ├── flaskr/ - │   ├── __init__.py - │   ├── db.py - │   ├── schema.sql - │   ├── auth.py - │   ├── blog.py - │   ├── templates/ - │   │ ├── base.html - │   │ ├── auth/ - │   │ │   ├── login.html - │   │ │   └── register.html - │   │ └── blog/ - │   │ ├── create.html - │   │ ├── index.html - │   │ └── update.html - │   └── static/ - │      └── style.css + │ ├── __init__.py + │ ├── db.py + │ ├── schema.sql + │ ├── auth.py + │ ├── blog.py + │ ├── templates/ + │ │ ├── base.html + │ │ ├── auth/ + │ │ │ ├── login.html + │ │ │ └── register.html + │ │ └── blog/ + │ │ ├── create.html + │ │ ├── index.html + │ │ └── update.html + │ └── static/ + │ └── style.css ├── tests/ - │   ├── conftest.py - │   ├── data.sql - │   ├── test_factory.py - │   ├── test_db.py - │  ├── test_auth.py - │  └── test_blog.py + │ ├── conftest.py + │ ├── data.sql + │ ├── test_factory.py + │ ├── test_db.py + │ ├── test_auth.py + │ └── test_blog.py ├── venv/ ├── setup.py └── MANIFEST.in From 2e10fc24a13f16e6fb07edc61c8398f74ace2492 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 16 Nov 2021 08:38:20 -0800 Subject: [PATCH 2/4] document address already in use error --- docs/cli.rst | 5 +++++ docs/quickstart.rst | 5 +++++ docs/server.rst | 41 +++++++++++++++++++++++++++++++++++++++ docs/tutorial/factory.rst | 5 +++++ 4 files changed, 56 insertions(+) diff --git a/docs/cli.rst b/docs/cli.rst index 6036cb2d..d758ddcc 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -103,6 +103,11 @@ replaces the :meth:`Flask.run` method in most cases. :: is provided for convenience, but is not designed to be particularly secure, stable, or efficient. See :doc:`/deploying/index` for how to run in production. +If another program is already using port 5000, you'll see +``OSError: [Errno 98]`` or ``OSError: [WinError 10013]`` when the +server tries to start. See :ref:`address-already-in-use` for how to +handle that. + Open a Shell ------------ diff --git a/docs/quickstart.rst b/docs/quickstart.rst index e07e8dbf..283b8fc3 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -83,6 +83,11 @@ deployment options see :doc:`deploying/index`. Now head over to http://127.0.0.1:5000/, and you should see your hello world greeting. +If another program is already using port 5000, you'll see +``OSError: [Errno 98]`` or ``OSError: [WinError 10013]`` when the +server tries to start. See :ref:`address-already-in-use` for how to +handle that. + .. _public-server: .. admonition:: Externally Visible Server diff --git a/docs/server.rst b/docs/server.rst index 71704e4a..c12f502c 100644 --- a/docs/server.rst +++ b/docs/server.rst @@ -64,6 +64,47 @@ and using the CLI. above. +.. _address-already-in-use: + +Address already in use +~~~~~~~~~~~~~~~~~~~~~~ + +If another program is already using port 5000, you'll see an ``OSError`` +when the server tries to start. It may have one of the following +messages: + +- ``OSError: [Errno 98] Address already in use`` +- ``OSError: [WinError 10013] An attempt was made to access a socket + in a way forbidden by its access permissions`` + +Either identify and stop the other program, or use +``flask run --port 5001`` to pick a different port. + +You can use ``netstat`` to identify what process id is using a port, +then use other operating system tools stop that process. The following +example shows that process id 6847 is using port 5000. + +.. tabs:: + + .. group-tab:: Linux/Mac + + .. code-block:: text + + $ netstat -nlp | grep 5000 + tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 6847/python + + .. group-tab:: Windows + + .. code-block:: text + + > netstat -ano | findstr 5000 + TCP 127.0.0.1:5000 0.0.0.0:0 LISTENING 6847 + +MacOS Monterey and later automatically starts a service that uses port +5000. To disable the service, got to System Preferences, Sharing, and +disable "AirPlay Receiver". + + Lazy or Eager Loading ~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/tutorial/factory.rst b/docs/tutorial/factory.rst index ade5d40b..c4a10a6d 100644 --- a/docs/tutorial/factory.rst +++ b/docs/tutorial/factory.rst @@ -177,4 +177,9 @@ Visit http://127.0.0.1:5000/hello in a browser and you should see the "Hello, World!" message. Congratulations, you're now running your Flask web application! +If another program is already using port 5000, you'll see +``OSError: [Errno 98]`` or ``OSError: [WinError 10013]`` when the +server tries to start. See :ref:`address-already-in-use` for how to +handle that. + Continue to :doc:`database`. From f16524ea1de682db50ee18a91b5204a834995b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Gmach?= Date: Thu, 16 Dec 2021 04:28:09 +0100 Subject: [PATCH 3/4] fix typo --- docs/server.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/server.rst b/docs/server.rst index c12f502c..446d5be8 100644 --- a/docs/server.rst +++ b/docs/server.rst @@ -101,7 +101,7 @@ example shows that process id 6847 is using port 5000. TCP 127.0.0.1:5000 0.0.0.0:0 LISTENING 6847 MacOS Monterey and later automatically starts a service that uses port -5000. To disable the service, got to System Preferences, Sharing, and +5000. To disable the service, go to System Preferences, Sharing, and disable "AirPlay Receiver". From 9d36623db1e9535eae7243a807079a54897efcc9 Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 22 Dec 2021 14:26:34 -0800 Subject: [PATCH 4/4] update requirements --- .pre-commit-config.yaml | 4 ++-- requirements/dev.txt | 47 +++++++++++++++++++++-------------------- requirements/docs.txt | 16 +++++++------- requirements/tests.txt | 6 +++--- requirements/typing.txt | 12 +++++------ src/flask/helpers.py | 2 +- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a78c1719..cdd59442 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.29.0 + rev: v2.29.1 hooks: - id: pyupgrade args: ["--py36-plus"] @@ -14,7 +14,7 @@ repos: files: "^(?!examples/)" args: ["--application-directories", "src"] - repo: https://github.com/psf/black - rev: 21.10b0 + rev: 21.12b0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 diff --git a/requirements/dev.txt b/requirements/dev.txt index 33493af3..456cb986 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,7 +12,7 @@ attrs==21.2.0 # via pytest babel==2.9.1 # via sphinx -backports.entry-points-selectable==1.1.0 +backports.entry-points-selectable==1.1.1 # via virtualenv blinker==1.4 # via -r requirements/tests.in @@ -22,49 +22,49 @@ cffi==1.15.0 # via cryptography cfgv==3.3.1 # via pre-commit -charset-normalizer==2.0.7 +charset-normalizer==2.0.9 # via requests click==8.0.3 # via pip-tools -cryptography==35.0.0 +cryptography==36.0.1 # via -r requirements/typing.in -distlib==0.3.3 +distlib==0.3.4 # via virtualenv docutils==0.16 # via # sphinx # sphinx-tabs -filelock==3.3.2 +filelock==3.4.0 # via # tox # virtualenv greenlet==1.1.2 ; python_version < "3.11" # via -r requirements/tests.in -identify==2.3.3 +identify==2.4.0 # via pre-commit idna==3.3 # via requests -imagesize==1.2.0 +imagesize==1.3.0 # via sphinx iniconfig==1.1.1 # via pytest -jinja2==3.0.2 +jinja2==3.0.3 # via sphinx markupsafe==2.0.1 # via jinja2 -mypy==0.910 +mypy==0.930 # via -r requirements/typing.in mypy-extensions==0.4.3 # via mypy nodeenv==1.6.0 # via pre-commit -packaging==21.2 +packaging==21.3 # via # pallets-sphinx-themes # pytest # sphinx # tox -pallets-sphinx-themes==2.0.1 +pallets-sphinx-themes==2.0.2 # via -r requirements/docs.in pep517==0.12.0 # via pip-tools @@ -76,23 +76,23 @@ pluggy==1.0.0 # via # pytest # tox -pre-commit==2.15.0 +pre-commit==2.16.0 # via -r requirements/dev.in py==1.11.0 # via # pytest # tox -pycparser==2.20 +pycparser==2.21 # via cffi pygments==2.10.0 # via # sphinx # sphinx-tabs -pyparsing==2.4.7 +pyparsing==3.0.6 # via packaging pytest==6.2.5 # via -r requirements/tests.in -python-dotenv==0.19.1 +python-dotenv==0.19.2 # via -r requirements/tests.in pytz==2021.3 # via babel @@ -104,9 +104,9 @@ six==1.16.0 # via # tox # virtualenv -snowballstemmer==2.1.0 +snowballstemmer==2.2.0 # via sphinx -sphinx==4.2.0 +sphinx==4.3.2 # via # -r requirements/docs.in # pallets-sphinx-themes @@ -133,21 +133,22 @@ sphinxcontrib-serializinghtml==1.1.5 # via sphinx toml==0.10.2 # via - # mypy # pre-commit # pytest # tox -tomli==1.2.2 - # via pep517 +tomli==2.0.0 + # via + # mypy + # pep517 tox==3.24.4 # via -r requirements/dev.in types-contextvars==2.4.0 # via -r requirements/typing.in types-dataclasses==0.6.1 # via -r requirements/typing.in -types-setuptools==57.4.2 +types-setuptools==57.4.4 # via -r requirements/typing.in -typing-extensions==3.10.0.2 +typing-extensions==4.0.1 # via mypy urllib3==1.26.7 # via requests @@ -155,7 +156,7 @@ virtualenv==20.10.0 # via # pre-commit # tox -wheel==0.37.0 +wheel==0.37.1 # via pip-tools # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/docs.txt b/requirements/docs.txt index 8f5fd06a..1b51a429 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -10,7 +10,7 @@ babel==2.9.1 # via sphinx certifi==2021.10.8 # via requests -charset-normalizer==2.0.7 +charset-normalizer==2.0.9 # via requests docutils==0.16 # via @@ -18,31 +18,31 @@ docutils==0.16 # sphinx-tabs idna==3.3 # via requests -imagesize==1.2.0 +imagesize==1.3.0 # via sphinx -jinja2==3.0.2 +jinja2==3.0.3 # via sphinx markupsafe==2.0.1 # via jinja2 -packaging==21.2 +packaging==21.3 # via # pallets-sphinx-themes # sphinx -pallets-sphinx-themes==2.0.1 +pallets-sphinx-themes==2.0.2 # via -r requirements/docs.in pygments==2.10.0 # via # sphinx # sphinx-tabs -pyparsing==2.4.7 +pyparsing==3.0.6 # via packaging pytz==2021.3 # via babel requests==2.26.0 # via sphinx -snowballstemmer==2.1.0 +snowballstemmer==2.2.0 # via sphinx -sphinx==4.2.0 +sphinx==4.3.2 # via # -r requirements/docs.in # pallets-sphinx-themes diff --git a/requirements/tests.txt b/requirements/tests.txt index 4e4247f5..f764cb7a 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -14,17 +14,17 @@ greenlet==1.1.2 ; python_version < "3.11" # via -r requirements/tests.in iniconfig==1.1.1 # via pytest -packaging==21.2 +packaging==21.3 # via pytest pluggy==1.0.0 # via pytest py==1.11.0 # via pytest -pyparsing==2.4.7 +pyparsing==3.0.6 # via packaging pytest==6.2.5 # via -r requirements/tests.in -python-dotenv==0.19.1 +python-dotenv==0.19.2 # via -r requirements/tests.in toml==0.10.2 # via pytest diff --git a/requirements/typing.txt b/requirements/typing.txt index 2be7465a..5e1982a6 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -6,21 +6,21 @@ # cffi==1.15.0 # via cryptography -cryptography==35.0.0 +cryptography==36.0.1 # via -r requirements/typing.in -mypy==0.910 +mypy==0.930 # via -r requirements/typing.in mypy-extensions==0.4.3 # via mypy -pycparser==2.20 +pycparser==2.21 # via cffi -toml==0.10.2 +tomli==2.0.0 # via mypy types-contextvars==2.4.0 # via -r requirements/typing.in types-dataclasses==0.6.1 # via -r requirements/typing.in -types-setuptools==57.4.2 +types-setuptools==57.4.4 # via -r requirements/typing.in -typing-extensions==3.10.0.2 +typing-extensions==4.0.1 # via mypy diff --git a/src/flask/helpers.py b/src/flask/helpers.py index 7b8b0870..43597801 100644 --- a/src/flask/helpers.py +++ b/src/flask/helpers.py @@ -714,7 +714,7 @@ def get_root_path(import_name: str) -> str: # Module already imported and has a file attribute. Use that first. mod = sys.modules.get(import_name) - if mod is not None and hasattr(mod, "__file__"): + if mod is not None and hasattr(mod, "__file__") and mod.__file__ is not None: return os.path.dirname(os.path.abspath(mod.__file__)) # Next attempt: check the loader.