Skip to content

Encoding problems when body contains non ascii chars #40

Open

Description

@lucasbrunialti

First, j0057 that's a really nice project! :)

Using Python2.7 and running the following command raises an exception:

githubrelease release Cobliteam/ommited edit v1.0.1-dev.3 --body 'Merges since 2018-01-24 18:38:46 +0000: - message with non ascii char: … '

Exception traceback:

Traceback (most recent call last):
  File "/home/travis/build/Cobliteam/ommited/venv/bin/githubrelease", line 11, in <module>
    sys.exit(main())
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/click/decorators.py", line 27, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/github_release.py", line 482, in _cli_release_edit
    gh_release_edit(*args, **kwargs)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/github_release.py", line 116, in with_check_for_credentials
    return func(*args, **kwargs)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/github_release.py", line 497, in gh_release_edit
    patch_release(repo_name, current_tag_name, **attributes)
  File "/home/travis/build/Cobliteam/ommited/venv/local/lib/python2.7/site-packages/github_release.py", line 362, in patch_release
    current_tag_name, "\n  ".join(updated)))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 167: ordinal not in range(128)

Activity

  1. lucasbrunialti commented on Jan 27, 2018

    @lucasbrunialti
    ContributorAuthor

    I think a simple # -*- coding: utf-8 -*- in the header solve the problem, I'm trying a fix, can you predict any problem that this can cause?

    Also, I'm having trouble running tests locally, the function do_commit can not find the VERSION file, so it fails many tests. I can make a fix for that too, but I don't know if I've just missed some setup...

    Thank you.

  2. jcfr commented on Jan 27, 2018

    @jcfr
    Collaborator
  3. added 2 commits that reference this issue on Jan 27, 2018
    8d31dba
    c348170
  4. lucasbrunialti commented on Jan 31, 2018

    @lucasbrunialti
    ContributorAuthor

    We also had to set PYTHONIOENCODING=utf8 (we also use travis)...

  5. added a commit that references this issue on Jan 31, 2018
    949cb88
  6. jcfr commented on Jan 31, 2018

    @jcfr
    Collaborator

    Trying to reproduce the encoding issue locally, I tried the following:

    $ mkvirtualenv test-issue-40
    
    $ python --version 
    Python 2.7.10
    
    $ pip install githubrelease
    $ githubrelease release jcfr/sandbox edit 1.0.0 --body 'This is a message with non ascii chars: …❄'
    updating '1.0.0' release: 
      body: None -> 'This is a message with non ascii chars: …❄'
    
    $ python -c "import locale; print(locale.getpreferredencoding())"
    UTF-8
    

    but this doesn't trigger the error

  7. lucasbrunialti commented on Jan 31, 2018

    @lucasbrunialti
    ContributorAuthor

    I'm thinking the problem is not with the github-release itself, but with python's io encoding... if sys.stdout.encoding is None, then a simple print of a utf8 encoding string will raise an exception, because the default sysout is ascii encoding.
    I just don't know if /pull/43 fix a bug that we could not find...

  8. jcfr commented on Mar 26, 2018

    @jcfr
    Collaborator

    Could this be related to http://bugs.python.org/issue19846

    And here is a quote from https://bugs.python.org/issue19846#msg205545

    At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
    
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions