Unsupported operand type for NoneType and str

I get a message saying:

Traceback (most recent call last):
 File "/var/www/fosa/error_supressor.py", line 46, in <module>
   sys.stderr.write(latest + '\n')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

I’ve been trying to solve this problem for several days now, but to be honest, I'm a rocky programmer. Therefore, let me build a problem and see if there is a patient who can save time on solving the modest problem of a stranger :-)

Also, 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'
+3
source share
2 answers
  • Something is tied Noneto latest. Find out what it is and correct your logical mistake.

  • Something is tied Noneto course. Drawing etc.

+4
source

, : - latest - course - None

python , , , , , "null", None. . , get(pk) , None, pk. , :

- :

if latest is None:
     # do something
else:
     sys.stderr.write(latest + '\n')

, ,

sys.stderr.write('%s\n' % latest) #so that latest can be of any type

sys.stderr.write(latest + '\n')
+3

Source: https://habr.com/ru/post/1786012/


All Articles