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

  • Home
  • SEARCH
  • 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 8695781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:07:12+00:00 2026-06-13T01:07:12+00:00

This following is from the django source code ( Django-1.41/django/utils/encoding.py ); try: s =

  • 0

This following is from the django source code (Django-1.41/django/utils/encoding.py);

try:
    s = unicode(str(s), encoding, errors)
except UnicodeEncodeError:
    if not isinstance(s, Exception):
        raise

    # If we get to here, the caller has passed in an Exception
    # subclass populated with non-ASCII data without special
    # handling to display as a string. We need to handle this
    # without raising a further exception. We do an
    # approximation to what the Exception's standard str()
    # output should be.
    s = u' '.join([force_unicode(arg, encoding, strings_only,
        errors) for arg in s])

My question is: In which case will s be an instance of Exception?
when s is an instance of Exception, and s have neither str or repr attribute. Than this situation happen. Is this right?

  • 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-06-13T01:07:14+00:00Added an answer on June 13, 2026 at 1:07 am

    s will be an exception if someone called the force_unicode function with a subclass of Exception and the message includes unicode characters.

    s = Exception("\xd0\x91".decode("utf-8"))
    # this will now throw a UnicodeEncodeError
    unicode(str(s), 'utf-8', 'strict')
    

    If the code in the try block fails then nothing will be assigned to s, so s will remain what the function was initially called with.

    Since Exception inherits from object, and object has had the __unicode__ method since Python 2.5, it might be the case that this code existed for Python 2.4 and is now obsolete.

    UPDATE:
    After opening a pull request, this code has now been removed from the Django source: https://github.com/django/django/commit/ce1eb320e59b577a600eb84d7f423a1897be3576

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried installing django-utils from source code from github and using pip. The installation
following up from yesterday... This portion of the code does work. $(document).ready(function(){ $('#listMenu a').click(function
I have the following code in the urls.py in mysite project. /mysite/urls.py from django.conf.urls.defaults
Following from this: Every specific weekday, sql and php I got this: deals_bookings.everyWeekDay =
Okay, this is following on from my previous question reguarding performing a simple ajax
I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,
I came across this in the following context from B. Pfaff's Analysis of Integrated
I am learning GWT, so I am following this tutorial from Google GWT https://developers.google.com/web-toolkit/tools/gwtdesigner/tutorials/stockwatcher
Following on from this question , I am interested in finding out how you
following on from this question (Developing to an interface with TDD), I'm still having

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.