wsgi problem: str-unicode return-type mismatch

Asked by nelko on 2012-05-15

Hi,

I have a problem. When I'm running my webservice (using apache2, python 2.6, mod_wsgi 2.0), sometimes I get this error:
Return-type mismatch in WebService::Get_ToAndCC: Expected <type 'unicode'> recieved <type 'str'>
or
Return-type mismatch in WebService::Get_ToAndCC: Expected <type 'str> recieved <type 'unicode'>

It's strange because sometimes the Get_ToAndCC method run successfull more times, and just one time I get this error.
Moreover I print the return string type to an error log file and it's 'unicode'. I can't understand how can I get a"Expected <type 'str>" message when there is not any string which type is 'str'.
How does it possible?
I think this is caused by wsgi because when is run the webservice with ladon2.6ctl testserve command it works fine.

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
No assignee Edit question
Solved by:
nelko
Solved:
2012-05-22
Last query:
2012-05-22
Last reply:
2012-05-19
nelko (szabonelli) said : #1

I noticed that in the error log file the result string of a method is 'unicode' until I get the error because then I become 'str'.
How changes the type of a string suddenly in the same method?

jsgaarde (jakob-simon-gaarde) said : #2

Hi Nelko.

Please always pastebin.com an example :-)

The only thing I can say is that Ladon is telling you that you are returning values with wrong types. If you have told Ladon that your method should return unicode (btw: You should use ladon.compat's PORTABLE_STRING instead if you want to ease transition to Python 3) then you have to return unicode. That means u"" (unicode) not "" (str)

Best Regards
Jakob Simon-Gaarde

nelko (szabonelli) said : #3

Hi Jacob,

I solved the problem....The wsgi running mode caused the problem, because apache always killed my database connection after about one minute, and some method returned empty string as exception what I didn't convert to unicode....
It took 2 days while I found it.....And then I set wsgi daemon mode and everything worked.