Unsupported operand type for NoneType and str
I get a message that states:
Traceback (most recent call last):
File "/var/www/fosa/error_supressor.py", line 46, in <module>开发者_JAVA技巧;
sys.stderr.write(latest + '\n')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
I have been trying to solve this problem for days now but honestly I'm a rocky programmer. So let's line up the problem and see if there is a patient person that can spare some time solving a humble stranger's problem :-)
Besides that when I check my error log I find this error message, which I suspect is related:
File "/var/www/fosa/app/controllers/client/client.py", line 601, in detail
if not course.bookable or not course.school.partner.active: # both objects are boolean
AttributeError: 'NoneType' object has no attribute 'bookable'
Something is binding
Nonetolatest. Figure out what it is and fix your logic error.Something is binding
Nonetocourse. Figure etc.
Obviously from the traceback, one has:
- latest is None
- course is None
A common pattern in python is to have variable names always be bound to a unique type, except when the most meaningful value that one can assign is a 'null' value, in which case you'd make the variable equal to None. E.g. say get(pk) returns an object from the DB, but it returns None when there's no object for the key pk. To fix the bug i'd do this:
Write something such as:
if latest is None:
# do something
else:
sys.stderr.write(latest + '\n')
or maybe
sys.stderr.write('%s\n' % latest) #so that latest can be of any type
instead of
sys.stderr.write(latest + '\n')
加载中,请稍侯......
精彩评论