我正在编写一个Python程序以连接到Kafka并读取/写入消息。
执行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版本6.10(圣地亚哥) Python3-3.7.1-Anaconda3 Python Python3路径-/ opt / local / bgdatapp / anaconda3 / bin / python Kerberos-5 卡夫卡-Cloudera 13.1
我能够从外壳程序访问我的kafka,并且能够推送和阅读消息。
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
从anaconda python模拟相同内容会引发错误。
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))
错误:
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
您能建议解决此问题的任何修补程序吗?
谢谢
答案 0 :(得分:0)
这里实际上有两个错误。首先是gssapi导入错误;第二个是gc / del(self._sock AttributeError)期间的错误。第二个错误只是一个错误。我们将在下一个版本中对其进行修复。但是,假设您修复了gssapi导入错误,那么第二个AttributeError应该不会发生。
好的,那么您安装了什么gssapi库?您是否可以在自己的环境中做到这一点?
from gssapi.raw.misc import GSSError
您似乎已安装了较旧/已弃用的python-gssapi模块。您想要一个:https://pypi.org/project/gssapi/(不是这个:https://pypi.org/project/python-gssapi/)