Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1102911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:15:36+00:00 2026-05-17T01:15:36+00:00

I have a weird error when try to redirect a exception to STDERR. I

  • 0

I have a weird error when try to redirect a exception to STDERR.

I have a script that is use to load several “plugins”, working as main entry program. The plugins do stuff like connect to databases, parsing text data, connect to web services, etc…

Is like this:

   try:
        Run plugins here...
        #All was ok!
        print "Ok!"
        sys.exit(0)
    except Exception,e:
        sys.stderr.writelines([unicode(e),u'\n',u'\n'])

        traceback.print_exc(file=sys.stderr)
        sys.exit(-1)

This is executed in the command-line, and sometimes I get the error:

TypeError: writelines() argument must be a sequence of strings

I have no clue how in this earth a Exception is not returning as a string here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:15:36+00:00Added an answer on May 17, 2026 at 1:15 am

    I finally figure this out.

    This happend when:

    try:
       raise Exception(u'Error with unicode chars')
    except:
      sys.stderr.write(u'%s\n\n' % e)
    

    I hack with this (from activestate community):

    def safe_unicode(obj, * args):
        """ return the unicode representation of obj """
        try:
            return unicode(obj, * args)
        except UnicodeDecodeError:
            # obj is byte string
            ascii_text = str(obj).encode('string_escape')
            return unicode(ascii_text)
    
    def safe_str(obj):
        """ return the byte string representation of obj """
        try:
            return str(obj)
        except UnicodeEncodeError:
            # obj is unicode
            return unicode(obj).encode('unicode_escape')
    
    
     #code
     except Exception,e:
            sys.stderr.write(u'%s\n\n' % safe_unicode(safe_str(e)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a bug where I have an MFC application that does weird
i'm having an weird problem, my project have a login page, that's working, but
I have a weird error that I cannot seem to find any documentation or
I have a weird error in my flask application. Problem is that the code
I have run into a very weird issue. I have several working Fitnesse tests
So, I have this very weird error - Some advanced PHP devs might also
I am facing a weird error.I have set up my code in IntelliJ Idea.
I have come across a very weird error. I'm on Solaris 10, using Ruby
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I have a weird question. After profiling my code several times with NYTProf. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.