Skip to content

Instantly share code, notes, and snippets.

@weijia
Created September 30, 2014 05:45
Show Gist options
  • Save weijia/a5d8b47d458eb66c45f7 to your computer and use it in GitHub Desktop.
Save weijia/a5d8b47d458eb66c45f7 to your computer and use it in GitHub Desktop.
encoding_error_workaround_for_saltstack_state.py
def smart_encoding(item_or_str):
target_encoding = "utf8"
if type(item_or_str) == unicode:
return item_or_str.encode(target_encoding, "replace")
else:
if type(item_or_str) == list:
res = []
for i in item_or_str:
res.append(smart_encoding(i))
return res
return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment