I have found out how to label using multiple attributes via an expression and python. What I have is as follows:

[ID] + '\n' + [Notes]

An ID example is "MH108" and a notes example is "buried, no access". I have used similar code successfully in the past, but in the current situation I get the following error and cannot figure out what I am missing.

The expression contains and error.
Modify the expression and try again.

Error 0 on line 0
Error running expressions:
Traceback (most recent call last):
Files “<expression>”, line 1, in <module>
File “<string>”, line 2, in esri_FindLabel
TypeError: coercing to Unicode: need string or buffer, NoneType found

enter image description here

  • Can you please show us a sample of your values in ID and NOTES? – Midavalo Feb 3 '17 at 22:45
  • Please always include error messages as text rather than only pictures. That way they are available to future searches and can be read on all devices more easily. – PolyGeo Feb 3 '17 at 23:36
  • Can you confirm there are no special characters at all in any of the field values? Is the expression you show above exactly how you have it in your label expression box (the error message is covering that in the screenshot) – Midavalo Feb 4 '17 at 1:21
  • Turns out the @Midavalo your answer below helped me out. There were NULL values, because all the assets do not have notes on them. I removed the NULL values by selecting them and using field calulate with "". I assume that I should answer my own question with the steps that I did? – LandArch Feb 4 '17 at 13:20
  • @PolyGeo - on the surface you are correct that this is a very similar question, but if you dive down into it there is more. The fact the NULL's caused an issue and simply doing as the other post states or the first answer in this post, provided a label with NULL's. Hence my comment above since I don't know how to proceed with the correct answer. – LandArch Feb 6 '17 at 17:11

It looks like one of your field values isn't a string already (the [ID] field is possibly a number, or one of the fields contains a NULL), so using + to concatenate them may not work.

Use python string formatting to get around concatenating numbers and strings:

"{0}\n{1}".format([ID], [Notes])
| improve this answer | |

That error is saying one or more of your field types is neither a string nor a buffer. You can check your field types or try:

str([ID]) + '\n' + str([Notes])

My guess is it's the ID as Notes are usually strings.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.