Wednesday, February 25, 2015

Re: TypeError: __str__ returned non-string (type bytes)

Erik and James

I really appreciate your feedback. The problem is resolved. It was related to py3 development and py2 in production. Erik had hit the nail on the head which I discovered when I went looking at why other tests were passing and those two were not. I had been inconsistent in implementing @python_2_unicode_compatible

Thank you again

Mike

On Wednesday, February 25, 2015 at 9:08:45 PM UTC+11, Erik Cederstrand wrote:

> Den 25/02/2015 kl. 05.33 skrev Mike Dewhirst <mi...@dewhirst.com.au>:
>
> ======================================================================
> ERROR: test_checkreference_exp (substance.tests.test_substance.TestSubstance)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "C:\Users\mike\env\xxdx3\ssds\substance\tests\test_substance.py", line 57, in test_checkreference_exp
>    self.assertEqual(subst.checkreference('1'), True)
>  File "C:\Users\mike\env\xxdx3\ssds\substance\models\substance.py", line 449, in checkreference
>    if checkit(self, ref):
>  File "C:\Users\mike\env\xxdx3\ssds\substance\models\substance.py", line 441, in checkit
>    val = u"{0}".format(obj.__dict__[field])
> TypeError: __str__ returned non-string (type bytes)

"obj.__dict__[field]" returns an object that has a __str__ method (format() calls the __str__ method of the object to convert it to a string). The __str__ method should only return unicode data but is returning byte strings. What does "obj.__dict__[field]" return, and can you show us the __str__ method of that class?

Erik

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/708ead8d-ba38-4676-8f2f-fc10b2ad4aab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment