synclabs
synclabs

Reputation: 277

Can't find the cause "TypeError: coercing to Unicode: need string or buffer, NoneType found"

I'm getting this error from production server:

 File "/home/example/svn/libs/django/core/handlers/base.py", line 100, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/home/example/svn/src/app/../app/libs/auth/decorators.py", line 125, in __call__
   return self.view_func(request, *args, **kwargs)

 File "/home/example/svn/src/app/../app/membership/decorators.py", line 64, in __call__
   return self.view_func(request, *args, **kwargs)

 File "/home/example/svn/src/app/../app/site/views/system/invoices.py", line 168, in send_via_email_form
   return SendViaEmailFormPage(request, pk, what, sending_type).custom()

 File "/home/example/svn/src/app/../app/security/security.py", line 99, in execute
   return func(*args, **kw)

 File "/home/example/svn/src/app/../app/site/views/system/invoices.py", line 405, in custom
   return self.custom_response or self.response()

 File "/home/example/svn/src/app/../app/security/security.py", line 99, in execute
   return func(*args, **kw)

 File "/home/example/svn/src/app/../app/libs/pages/__init__.py", line 235, in response
   response = render_to_response(self.template, self.data, context_instance=RequestContext(self.request, self.data))

 File "/home/example/svn/libs/django/shortcuts/__init__.py", line 20, in render_to_response
   return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

 File "/home/example/svn/libs/django/template/loader.py", line 186, in render_to_string
   return t.render(context_instance)

 File "/home/example/svn/libs/django/template/__init__.py", line 173, in render
   return self._render(context)

 File "/home/example/svn/libs/django/template/__init__.py", line 167, in _render
   return self.nodelist.render(context)

 File "/home/example/svn/libs/django/template/__init__.py", line 796, in render
   bits.append(self.render_node(node, context))

 File "/home/example/svn/libs/django/template/__init__.py", line 809, in render_node
   return node.render(context)

 File "/home/example/svn/libs/django/template/__init__.py", line 849, in render
   return _render_value_in_context(output, context)

 File "/home/example/svn/libs/django/template/__init__.py", line 829, in _render_value_in_context
   value = force_unicode(value)

 File "/home/example/svn/libs/django/utils/encoding.py", line 66, in force_unicode
   s = unicode(s)

TypeError: coercing to Unicode: need string or buffer, NoneType found

Unfortunely I can't reproduce it in any way on development server. The exception is not helping much. From django code:

if hasattr(s, '__unicode__'):
   s = unicode(s)

If it has 'unicode' attribute, why NoneType is found. Do I have to dig into python source code for this one ? Would appreciate any help.

Thanks.

Upvotes: 0

Views: 8588

Answers (1)

S.Lott
S.Lott

Reputation: 391820

Focus on just this portion of the traceback. This looks like code you wrote.

 File "/home/example/svn/src/app/../app/membership/decorators.py", line 64, in __call__
   return self.view_func(request, *args, **kwargs)

 File "/home/example/svn/src/app/../app/site/views/system/invoices.py", line 168, in send_via_email_form
   return SendViaEmailFormPage(request, pk, what, sending_type).custom()

 File "/home/example/svn/src/app/../app/security/security.py", line 99, in execute
   return func(*args, **kw)

 File "/home/example/svn/src/app/../app/site/views/system/invoices.py", line 405, in custom
   return self.custom_response or self.response()

 File "/home/example/svn/src/app/../app/security/security.py", line 99, in execute
   return func(*args, **kw)

 File "/home/example/svn/src/app/../app/libs/pages/__init__.py", line 235, in response
   response = render_to_response(self.template, self.data, context_instance=RequestContext(self.request, self.data))

Somewhere there's a None where there should have been a String.

In many cases, this arises because have an unauthenticated user the default Anonymous user sometimes lacks the various attribute values that your "real" users have. It doesn't have problems in development because you have cookies on your development PC that allow you to login. You may be missing some cookie from your production server, and aren't getting logged in.

It helps to add lots and lots of logging output to the view function involved in this so that you can read through the Apache logs and see where things are breaking.

Upvotes: 1

Related Questions