From ec185cf416adce98e0a3ef338720091c0e2a53fe Mon Sep 17 00:00:00 2001 From: Crestez Dan Leonard Date: Mon, 28 Jul 2014 20:42:46 +0300 Subject: [PATCH] Fix encoding error when updating with redirected output 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. --- gitlab.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitlab.py b/gitlab.py index 7eb844fb4..a7ec48747 100644 --- a/gitlab.py +++ b/gitlab.py @@ -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 @@ -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,