Skip to content

Commit ec185cf

Browse files
committed
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.
1 parent e236fd9 commit ec185cf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gitlab.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def __init__(self, url, private_token=None,
8989
self.email = email
9090
self.password = password
9191
self.ssl_verify = ssl_verify
92+
# Gitlab should handle UTF-8
93+
self.gitlab_encoding = 'UTF-8'
9294

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

307309
try:
308310
r = requests.put(url, d,

0 commit comments

Comments
 (0)