# ColorBy(rep,value=None) results in RuntimeError

**URL:** https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263
**Category:** ParaView Support
**Tags:** python
**Created:** [January 21, 2021, 9:23am UTC](https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263 "2021-01-21T09:23:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![oponkork](https://discourse.paraview.org/user_avatar/discourse.paraview.org/oponkork/32/5733_2.png) [@oponkork](https://discourse.paraview.org/u/oponkork)
#### Post date: [January 21, 2021, 9:23am UTC](https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263/1 "2021-01-21T09:23:13Z")

</div>

Using `colorBy(rep,value=None)` in a python script results in the following error:

```
>>> Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/paraview/servermanager.py", line 3190, in GetAssociationFromString
    return ASSOCIATIONS[val]
KeyError: 'NONE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/paraview/servermanager.py", line 3193, in GetAssociationFromString
    return _LEGACY_ASSOCIATIONS[val]
KeyError: 'NONE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 59, in <module>
  File "<string>", line 53, in __streamlines
  File "/usr/lib/python3.9/site-packages/paraview/simple.py", line 581, in ColorBy
    rep.SetScalarColoring(None, servermanager.GetAssociationFromString(association))
  File "/usr/lib/python3.9/site-packages/paraview/servermanager.py", line 3195, in GetAssociationFromString
    raise RuntimeError ("invalid association string '%s'" % val)
RuntimeError: invalid association string 'NONE'
>>>

```

The following logic is executed.

In paraview/simple.py from line 580

```
if value == None:
    rep.SetScalarColoring(None, servermanager.GetAssociationFromString(association))

```

In paraview/servermanager.py from line 3185

```
def GetAssociationFromString(val):
    """Returns array association integer value from its string representation"""
    global ASSOCIATIONS, _LEGACY_ASSOCIATIONS
    val = str(val).upper()
    try:
        return ASSOCIATIONS[val]
    except KeyError:
        try:
            return _LEGACY_ASSOCIATIONS[val]
        except KeyError:
            raise RuntimeError ("invalid association string '%s'" % val)

```

None of the dictionaries (ASSOCIATIONS and \_LEGACY\_ASSOCIATIONS have a ‘NONE’ key.

```
ASSOCIATIONS = { 'POINTS' : 0, 'CELLS' : 1, 'FIELD' : 2, 'VERTICES' : 4, 'EDGES' : 5, 'ROWS' : 6}
_LEGACY_ASSOCIATIONS = { 'POINT_DATA' : 0, 'CELL_DATA' : 1 }
```

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [January 21, 2021, 9:35am UTC](https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263/2 "2021-01-21T09:35:02Z")

</div>

Which version of ParaView ?

---

<div class="post-metadata">

### Author: ![oponkork](https://discourse.paraview.org/user_avatar/discourse.paraview.org/oponkork/32/5733_2.png) [@oponkork](https://discourse.paraview.org/u/oponkork)
#### Post date: [January 21, 2021, 10:08am UTC](https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263/3 "2021-01-21T10:08:50Z")

</div>

paraview version 5.8.1

---

<div class="post-metadata">

### Author: ![oponkork](https://discourse.paraview.org/user_avatar/discourse.paraview.org/oponkork/32/5733_2.png) [@oponkork](https://discourse.paraview.org/u/oponkork)
#### Post date: [January 21, 2021, 12:24pm UTC](https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263/4 "2021-01-21T12:24:40Z")

</div>

Appending `'NONE':-1` to the ASSOSCIATION dictionary suppresses the error, but it is not a solution.

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [January 21, 2021, 4:01pm UTC](https://discourse.paraview.org/t/colorby-rep-value-none-results-in-runtimeerror/6263/5 "2021-01-21T16:01:30Z")

</div>

It seems in some case the data does not have default association … To avoid error in your code, you can try to add

```auto
rep.ColorArrayName = ['POINTS', '']

```

before calling ColorBy() …

@utkarsh.ayachit any idea ?  
This is reproducible (also in master) with the following

```python
from paraview.simple import *
Sphere()
r = Show()
# r.ColorArrayName = ['POINTS', '']
ColorBy(r, value=None)

```

This script generates error, uncomment the line and no more error.
