Skip to content

flexget history crashes when piping to less or redirecting to a file #1223

Description

@grr

Expected behaviour:

print history when piping output to less or redirecting to a file

Actual behaviour:

crashes with:
Could not start manager: 'ascii' codec can't encode character u'\u2013' in position 47: ordinal not in range(128)

Steps to reproduce:

flexget history | less
or
flexget history > history.txt

Additional information:

  • Flexget Version: 2.0.38
  • Python Version: 2.7.11
  • Installation method: git
  • OS and version: OS X

Activity

  1. Mirgolth commented on Jun 27, 2016

    @Mirgolth
    Contributor

    Maybe try to upgrade.
    I test on my setup with version 2.1.1 and don't face this issue.

  2. grr commented on Jun 27, 2016

    @grr
    Author

    I've been constantly upgrading to newest versions and am now on 2.1.1 and still getting the same error. flexget history | less no longer gives a stack trace, it just stops producing output, so if you scroll to end you see the history output just cuts short. But if you redirect the output you can still see the problem exists:

    $ flexget history > /tmp/flex.out
    Could not start manager: 'ascii' codec can't encode character u'\u2013' in position 47: ordinal not in range(128)
    
  3. liiight commented on Jun 27, 2016

    @liiight
    Member

    This has something to do with system encoding, It was asked before.
    Note that you can use the API for this as well:
    curl -X GET --header "Accept: application/json" "http://host:5050/api/history/?page=1&max=50" < /tmp/flex.out

  4. grr commented on Jun 27, 2016

    @grr
    Author

    and the encoding issue has been fixed in other commands in the past. the api only works if you run the daemon and many of us don't. i only run flexget via cron or the command line.

  5. grr commented on Jun 29, 2016

    @grr
    Author

    This works for me:

    $ git diff flexget/logger.py
    diff --git a/flexget/logger.py b/flexget/logger.py
    index fc6524b..626c948 100644
    --- a/flexget/logger.py
    +++ b/flexget/logger.py
    @@ -114,7 +114,8 @@ def console(text, *args, **kwargs):
        Accepts arguments like the `print` function does.
        """
        if not isinstance(text, str):
    -        text = str(text).encode(io_encoding, 'replace')
    +        text = str(text)
    +    text = text.encode(io_encoding, 'replace')
        kwargs['file'] = getattr(local_context, 'output', sys.stdout)
        print(text, *args, **kwargs)
        kwargs['file'].flush()  # flush to make sure the output is printed right away
    
  6. liiight commented on Jun 29, 2016

    @liiight
    Member

    Cool, wanna push a pr?

  7. grr commented on Aug 15, 2016

    @grr
    Author

    why was this labeled "Pending information"? ok, i'll answer the question- no i don't wanna push a pr, cause i only have access via phone these days. i gave you a 2-line patch, how is that insufficient?

  8. liiight commented on Aug 16, 2016

    @liiight
    Member

    This actually has been fixed on next branch with dcce2b5
    Will mark this as resolved when we merge that branch.

  9. liiight commented on Aug 17, 2016

    @liiight
    Member

    Fixed with dcce2b5

  10. liiight commented on Aug 18, 2016

    @liiight
    Member

    @grr can you confirm it's fixed?

  11. grr commented on Aug 22, 2016

    @grr
    Author

    yes, mostly. it doesn't crash now, but the new ascii colorization causes visual artifacts when piping through less. it should do something like this instead:
    if sys.stdout.isatty(): colorize()

  12. liiight commented on Aug 22, 2016

    @liiight
    Member

    That's a good idea, we'll see about adding it

  13. grr commented on Sep 23, 2016

    @grr
    Author

    This issue is happening again. Tried with flexget history | less and flexget series list all | less. #1407 is the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions