Search code examples
pythonapache-kafkanameerror

import kafka is giving "NameError: name 'true' is not defined"


I am trying to use kafka-python to stream csv data but while importing kafka, I'm getting below error. The funny thing is it was working last night and since morning its giving this error all of sudden.

NameError                                 Traceback (most recent call last)
<ipython-input-13-c237685c7217> in <module>
----> 1 import kafka

~/TweetStream/kafka.py in <module>
     29    "id": "interior-tolerance",
     30    "metadata": {
---> 31     "scrolled": true
     32    },`enter code here`
     33    "outputs": [

NameError: name 'true' is not defined

Solution

  • Are you sure you don't have a file named kafka (or perhaps a class or def) that could be overriding the default kafka-python module? If so, I would change its name or -- well, just change the name or put it in a subdirectory, as it'll get quite confusing and error-prone otherwise.

    It seems in your file you have a true on line 31 where it should be the python builtin True instead.

    ~/TweetStream/kafka.py in <module>
    
    ---> 31     "scrolled": true