Wednesday, February 25, 2015

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

> Den 25/02/2015 kl. 05.33 skrev Mike Dewhirst <miked@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/A41F5598-AC16-411E-8136-52BABB7B3640%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment