Skip to content

Commit

Permalink
Fix encoding error when updating with redirected output
Browse files Browse the repository at this point in the history
When output is redirected sys.stdout.encoding is None. Fix this by
always encoding to utf-8, assuming gitlab handles that. The encoding
used by the local system is irrelevant here.
  • Loading branch information
cdleonard committed Jul 28, 2014
1 parent e236fd9 commit ec185cf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gitlab.py
Expand Up @@ -89,6 +89,8 @@ def __init__(self, url, private_token=None,
self.email = email
self.password = password
self.ssl_verify = ssl_verify
# Gitlab should handle UTF-8
self.gitlab_encoding = 'UTF-8'

def auth(self):
"""Performs an authentication using either the private token, or the
Expand Down Expand Up @@ -302,7 +304,7 @@ def update(self, obj):
if type(v) in (int, str, bool):
d[k] = str(v)
elif type(v) == unicode:
d[k] = str(v.encode(sys.stdout.encoding, "replace"))
d[k] = str(v.encode(self.gitlab_encoding, "replace"))

try:
r = requests.put(url, d,
Expand Down

0 comments on commit ec185cf

Please sign in to comment.