Skip to content

Fixed encoding error while piped output #26

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

Closed
wants to merge 1 commit into from
Closed

Fixed encoding error while piped output #26

wants to merge 1 commit into from

Conversation

baldulin
Copy link

@baldulin baldulin commented May 8, 2014

If a ran python-gitlab with the -v option piping to another process
was not possible. This was due to the fact that sys.stdout.encoding
was set to None.
The problem is solved if the default encoding is used instead of
sys.stdout.encoding if it is set to None.

Here the Traceback:
Traceback (most recent call last):
File "/usr/bin/gitlab", line 5, in
pkg_resources.run_script('python-gitlab==0.6', 'gitlab')
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 528, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 1401, in run_script
exec(script_code, namespace, namespace)
File "/usr/lib/python2.7/site-packages/python_gitlab-0.6-py2.7.egg/EGG-INFO/scripts/gitlab", line 337, in

  File "build/bdist.linux-x86_64/egg/gitlab.py", line 554, in display
  File "build/bdist.linux-x86_64/egg/gitlab.py", line 589, in pretty_print
TypeError: encode() argument 1 must be string, not None

If a ran python-gitlab with the -v option piping to another process
was not possible. This was due to the fact that sys.stdout.encoding
was set to None.
The problem is solved if the default encoding is used if
sys.stdout.encoding is None.
@mrjohannchang
Copy link

How about use sys.stdout.encoding if sys.stdout.encoding is not None else sys.getdefaultencoding() instead? BTW, there are three sys.stdout.encoding.

@baldulin
Copy link
Author

You mean exchange those four lines with the one liner? I think that line will be to long then.

What there are three encodings safed like sys.stdout.encoding

@baldulin
Copy link
Author

Ah you mean line 305, yeah that would need some changes too.

@cdleonard
Copy link
Contributor

I also ran into this and made my own fix: https://github.com/cdleonard/python-gitlab/commits/master

I think at line 305 using sys.stdout.encoding or sys.getdefaultencoding() would be wrong. Instead strings should be encoded in a format that the gitlab API understands. Sadly they have some issues with that in upstream: https://github.com/gitlabhq/gitlabhq/issues/6244 so it's not clear what the correct format would be.

@baldulin
Copy link
Author

Yap that was my problem too. I'm not sure what encoding was intendet to be used.

@gpocentek
Copy link
Contributor

Hi,

I merged #27, which worked fine for me and was a bit cleaner IMO.

Thanks for tackling this anyway.

@gpocentek gpocentek closed this Aug 21, 2014
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

Successfully merging this pull request may close these issues.

4 participants