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

Zign gives an error when run on Windows #65

Open
graeme-carr opened this issue Feb 17, 2020 · 0 comments
Open

Zign gives an error when run on Windows #65

graeme-carr opened this issue Feb 17, 2020 · 0 comments

Comments

@graeme-carr
Copy link

graeme-carr commented Feb 17, 2020

On Windows, zign gives an error with the following stack:

  File "c:\...\appdata\local\programs\python\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\...\appdata\local\programs\python\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\...\AppData\Local\Programs\Python\Python38\scripts\ztoken.exe\__main__.py", line 7, in <module>
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\zign\cli.py", line 99, in main
    cli()
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 1114, in invoke
    return Command.invoke(self, ctx)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\zign\cli.py", line 34, in cli
    ctx.invoke(token)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\zign\cli.py", line 90, in token
    token = get_token_implicit_flow(name, authorize_url=authorize_url, token_url=token_url, client_id=client_id,
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\zign\api.py", line 255, in get_token_implicit_flow
    response = perform_implicit_flow(config)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\zign\api.py", line 193, in perform_implicit_flow
    info('Your browser has been opened to visit:\n\n\t{}\n'.format(browser_url))
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\clickclick\console.py", line 74, in info
    secho(msg, fg='blue', bold=True)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\clickclick\console.py", line 49, in secho
    click.secho(*args, **kwargs)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\termui.py", line 478, in secho
    return echo(message, file=file, nl=nl, err=err, color=color)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\utils.py", line 260, in echo
    file.write(message)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\_compat.py", line 630, in _safe_write
    return _write(s)
  File "c:\...\AppData\Roaming\Python\Python38\site-packages\colorama\ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "c:\...\AppData\Roaming\Python\Python38\site-packages\colorama\ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "c:\...\AppData\Roaming\Python\Python38\site-packages\colorama\ansitowin32.py", line 187, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\...\AppData\Roaming\Python\Python38\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\_winconsole.py", line 180, in write
    return self._text_stream.write(x)
  File "c:\...\appdata\local\programs\python\python38\lib\site-packages\click\_winconsole.py", line 164, in write
    raise OSError(self._get_error_message(GetLastError()))
OSError: Windows error 6

The cause of this is the following section of code in api.py:

        # Redirect stdout and stderr. In Linux, a message is outputted to stdout when opening the browser
        # (and then a message to stderr because it can't write).
        saved_stdout = os.dup(1)
        saved_stderr = os.dup(2)
        os.close(1)
        os.close(2)
        os.open(os.devnull, os.O_RDWR)
        try:
            webbrowser.open(browser_url, new=1, autoraise=True)
        finally:
            os.dup2(saved_stdout, 1)
            os.dup2(saved_stderr, 2)

The stdout / stderr redirection is not needed for Windows, and unlike on Linux, it looks as though the os.close(1) call is closing stdout itself, instead of the pointer to it. This means later attempts to write to stdout are failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant