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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ def _obj_to_str(obj):
s = ", ".join([GitlabObject._obj_to_str(x) for x in obj])
return "[ %s ]" % s
elif isinstance(obj, unicode):
return obj.encode(sys.stdout.encoding, "replace")
if sys.stdout.encoding is None:
return obj.encode(sys.getdefaultencoding(), "replace")
else:
return obj.encode(sys.stdout.encoding, "replace")

else:
return str(obj)

Expand All @@ -585,8 +589,14 @@ def pretty_print(self, depth=0):
if k == self.idAttr:
continue
v = self.__dict__[k]
pretty_k = k.replace('_', '-').encode(sys.stdout.encoding,
"replace")

if sys.stdout.encoding is None:
pretty_k = k.replace('_','-').encode(sys.getdefaultencoding(),
"replace")
else:
pretty_k = k.replace('_', '-').encode(sys.stdout.encoding,
"replace")

if isinstance(v, GitlabObject):
if depth == 0:
print("%s:" % pretty_k)
Expand Down