AttributeError: 'NoneType' object has no attribute 'replace'

I receive this error when executing the following script. I highlighted the section that’s causing the issue. col4.replace("’", “’’”)

Traceback (most recent call last):

File “event:actionPerformed”, line 25, in

AttributeError: ‘NoneType’ object has no attribute ‘replace’

Hello,

If you check the rows in the vwProductionCounts table in the LabelDesc column you should see one or more NULL values.

So when you query the database table and get the values for LabelDesc (row(3)) you get Python’s version of NULL which is None. And the None value does not have a “replace” method so you get the error you are getting.

You could make the default value for this column in the database an empty string so that you don’t get this error or handle the problem in another way.

Best,

I do not have control over the database I am connected to that’s why I am pulling these values and dumping them into our local database using this script. I checked that value and you are correct it is null. Is there a way around this with the script?

If you need to massage it you can try something like:

if row[3] == None: col4 = '' else: col4 = row[3]

You could also handle this in your query using COALESCE().

COALESCE(LabelDesc, ‘’)

will return an empty string if LabelDesc is NULL.