I am writing a python program to connect to Kafka and read/write message.
Producer error on executing python3 producer.py
File "/opt/local/bgdatapp/anaconda3/lib/python3.7/site-packages/kafka/conn.py", line 255, in init
assert gssapi is not None, 'GSSAPI lib not available'
AssertionError: GSSAPI lib not available
Exception ignored in: <function BrokerConnection.del at 0x7f715f4b3378>
Traceback (most recent call last):
File "/opt/local/bgdatapp/anaconda3/lib/python3.7/site-packages/kafka/conn.py", line 696, in del
self._close_socket()
File "/opt/local/bgdatapp/anaconda3/lib/python3.7/site-packages/kafka/conn.py", line 691, in _close_socket
if self._sock:
AttributeError: 'BrokerConnection' object has no attribute '_sock'
INFO:kafka.producer.kafka:Kafka producer closed
OS - Red Hat Enterprise Linux Server release 6.10 (Santiago) Python3 - 3.7.1 - Anaconda3 Python Python3 path - /opt/local/bgdatapp/anaconda3/bin/python Kerberos - 5 Kafka - Cloudera 13.1
I am able to access my kafka from shell and i am able to push and read messages.
kafka-console-producer --broker-list host.domain.com:9092 --topic Topic1 --producer.config client.properties
cat client.properties security.protocol=SASL_PLAINTEXT sasl.kerberos.service.name=kafka
Simulating the same from anaconda python is throwing error.
import os
import socket
import gssapi
import logging
from kafka import KafkaProducer
KAFKA_TOPIC = 'Topic1'
KAFKA_BROKERS = 'host.domain.com:9092'
os.environ['KAFKA_OPTS'] = '-Djava.security.auth.login.config=/opt/local/account1/jaas.conf'
logging.basicConfig(level=logging.INFO)
messages = [b'hello kafka', b'I am sending', b'3 test messages']
producer = KafkaProducer(bootstrap_servers=KAFKA_BROKERS, api_version=(0 , 10), security_protocol='SASL_PLAINTEXT', sasl_mechanism='GSSAPI', sasl_kerberos_service_name='kafka', max_request_size=3173440261)
for m in messages:
print (producer.send(KAFKA_TOPIC, m).get(timeout=30))
ERROR:
File "/opt/local/bgdatapp/anaconda3/lib/python3.7/site-packages/kafka/conn.py", line 255, in init
assert gssapi is not None, 'GSSAPI lib not available'
AssertionError: GSSAPI lib not available
Exception ignored in: <function BrokerConnection.del at 0x7f715f4b3378>
Traceback (most recent call last):
File "/opt/local/bgdatapp/anaconda3/lib/python3.7/site-packages/kafka/conn.py", line 696, in del
self._close_socket()
File "/opt/local/bgdatapp/anaconda3/lib/python3.7/site-packages/kafka/conn.py", line 691, in _close_socket
if self._sock:
AttributeError: 'BrokerConnection' object has no attribute '_sock'
INFO:kafka.producer.kafka:Kafka producer closed
Can you suggest any fix to resolve this issue?
Thanks