Opened 9 years ago

Closed 9 years ago

#4990 closed (worksforme)

Problems in HttpResponse __str__ method.

Reported by: Thomas Güttler <hv@…> Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by mtredinnick)


I got this exception:

UnicodeEncodeError at /.../
'ascii' codec can't encode character u'\xe4' in position 33614: ordinal not in range(128)

#  /home/modarch/wfbauantraege/wfba/ in process_exception
  # Send Debug Traceback as  Email to us
  81. html=smart_unicode(django.views.debug.technical_500_response(request, *sys.exc_info()), errors="replace") ...

# /home/modarch/python/lib64/python2.4/site-packages/django/utils/ in smart_unicode

  25. return force_unicode(s, encoding, strings_only, errors) ...

# /home/modarch/python/lib64/python2.4/site-packages/django/utils/ in force_unicode
  35. return s
  36. if not isinstance(s, basestring,):
  37.     if hasattr(s, '__unicode__'):
  38.         s = unicode(s)
  39.     else:

  40.         s = unicode(str(s), encoding, errors) ...

s is a django.http.HttpResponseServerError object.

This patch gives HttpResponse a __unicode__ method.

Attachments (1)

httpresponse-unicode.diff (413 bytes) - added by Thomas Güttler <hv@…> 9 years ago.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by Thomas Güttler <hv@…>

comment:1 Changed 9 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from HttpResponse.__unicode__ to Give HttpResponse a __unicode__ method
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 9 years ago by mtredinnick

  • Description modified (diff)
  • Has patch unset
  • Summary changed from Give HttpResponse a __unicode__ method to Problems in HttpResponse __str__ method.
  • Triage Stage changed from Ready for checkin to Accepted

This patch doesn't look correct. The Unicode and str representations would only be identical if all the data was guaranteed to be ASCII and that's not true for the "content" attribute. Plus there should at least be a call to unicode() in there somewhere so that the right type is returned (rather than assuming Python's C layer will correct the problem, which is kind of accidental).

Thinking about the actual problem report, the whole approach looks like it's covering over a different problem: what should the encoding of the content be and how to represent that correctly as UTF-8 (in __str__) or as Unicode (which is what the __unicode__ method must return)?

More thinking is required here. No question that something is going wrong, but I need to trace through our encoding assumptions so that we can lay down the right rules for how to treat the content. It's not immediately clear that a __unicode__ method is needed, since an HttpResponse is always sent as a sequence of bytes.

comment:3 Changed 9 years ago by Thomas Güttler <hv@…>

  • Resolution set to worksforme
  • Status changed from new to closed

The real problem was in views/ The error does not occur anymore.

Note: See TracTickets for help on using tickets.
Back to Top