- if type(string) == unicode:
- encoding = 'utf-8'
- if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
- encoding = sys.stdout.encoding
- return string.encode(encoding or 'utf-8', 'replace')
- else:
+ try:
+ if type(string) == unicode:
+ encoding = 'utf-8'
+ if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
+ encoding = sys.stdout.encoding
+ return string.encode(encoding or 'utf-8', 'replace')
+ else:
+ return str(string)
+ except: