Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.7.0 console=False cause error with Flask #7310

Closed
Shurelol opened this issue Dec 6, 2022 · 5 comments
Closed

5.7.0 console=False cause error with Flask #7310

Shurelol opened this issue Dec 6, 2022 · 5 comments

Comments

@Shurelol
Copy link

Shurelol commented Dec 6, 2022

flask output server banner by echo() in click\utils.py
image
image
image

in 5.7.0, if console=False in spec, the param file in echo() will be None and cause error
image

5.6.2 works fine

@Shurelol Shurelol added the triage Please triage and relabel this issue label Dec 6, 2022
@Shurelol Shurelol closed this as completed Dec 6, 2022
@bwoodsend
Copy link
Member

You can't write to stdout in windowed mode because sys.stdout is None. See https://pyinstaller.org/en/v5.7.0/CHANGES.html#incompatible-changes.

@bwoodsend bwoodsend added solution:invalid state:need info Need more information for solve or help. and removed triage Please triage and relabel this issue state:need info Need more information for solve or help. labels Dec 6, 2022
@rokm
Copy link
Member

rokm commented Dec 14, 2022

I've opened issue with click (pallets/click#2415) - as they are advertising click.utils.echo as replacement for print, they should be properly handling the case when console is unavailable.

@Shurelol
Copy link
Author

Shurelol commented Dec 14, 2022

thanks for your replay

as for now, my solution is that creat class NullWriter and set sys.stdout and sys.stderr in my program

class NullWriter:
    softspace = 0
    encoding = 'UTF-8'

    def write(*args):
        pass

    def flush(*args):
        pass

    # Some packages are checking if stdout/stderr is available (e.g., youtube-dl). For details, see #1883.
    def isatty(self):
        return False

sys.stdout = NullWriter()
sys.stderr = NullWriter()

@Shurelol Shurelol reopened this Dec 14, 2022
@rokm
Copy link
Member

rokm commented Dec 14, 2022

It's probably better to use sys.stdout = open(os.devnull, "w") and sys.stderr = open(os.devnull, "w") as in #7325 to get fully-compliant file-like interface instead of using the old NullWriter.

@rokm rokm closed this as completed Dec 14, 2022
@bwoodsend
Copy link
Member

That said, you really should not build any kind of web server with console=False. If someone tries to hack your website, all the tell tale exceptions in your logs as they feel out vulnerabilities to exploit will be lost to you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants