AttributeError:str对象没有属性解码(python、ubuntu)
我从Ubuntu控制台运行了一个python文件,得到了一个AttributeError。我不确定是什么问题。 下面是代码AttributeError:str对象没有属性解码(python、ubuntu),python,ubuntu,server,Python,Ubuntu,Server,我从Ubuntu控制台运行了一个python文件,得到了一个AttributeError。我不确定是什么问题。 下面是代码 import threading import json from config.DatabaseConfig import * from utils.Database import Database from utils.BotServer import BotServer from utils.Preprocess import Preprocess from mod
import threading
import json
from config.DatabaseConfig import *
from utils.Database import Database
from utils.BotServer import BotServer
from utils.Preprocess import Preprocess
from models.intent.IntentModel import IntentModel
from models.ner.NerModel import NerModel
from utils.FindAnswer import FindAnswer
# 전처리 객체 생성
p=Preprocess(word2index_dic='train_tools/dict/chatbot_dict.bin',
userdic='../Tokenizing/user_dic.txt')
# 의도 파악 모델
intent = IntentModel(model_name='models/intent/intent_model.h5', proprocess=p)
# 개체명 인식 모델
ner = NerModel(model_name='models/ner/ner_model.h5', proprocess=p)
def to_client(conn, addr, params):
db = params['db']
try:
db.connect() # 디비 연결
# 데이터 수신
read = conn.recv(2048) # 수신 데이터가 있을 때 까지 블로킹
print('===========================')
print('Connection from: %s' % str(addr))
if read is None or not read:
# 클라이언트 연결이 끊어지거나, 오류가 있는 경우
print('클라이언트 연결 끊어짐')
exit(0)
# json 데이터로 변환
recv_json_data = json.loads(read)
print("데이터 수신 : ", recv_json_data)
query = recv_json_data['Query']
# print(query) 여기 까지는 정상적으로 작동
# 의도 파악
intent_predict = intent.predict_class(query)
intent_name = intent.labels[intent_predict]
print(intent_name)
# 개체명 파악
ner_predicts = ner.predict(query)
ner_tags = ner.predict_tags(query)
# 답변 검색
try:
f = FindAnswer(db)
answer_text, answer_image = f.search(intent_name, ner_tags)
answer = f.tag_to_word(ner_predicts, answer_text)
except:
answer = "죄송해요 무슨 말인지 모르겠어요. 조금 더 공부 할게요."
answer_image = None
send_json_data_str = {
"Query" : query,
"Answer": answer,
"AnswerImage": answer_image,
"Intent": intent_name,
"NER": str(ner_predicts)
}
message = json.dumps(send_json_data_str)
print(message)
conn.send(message.encode())
except Exception as ex:
print(ex)
print("여기")
finally:
if db is not None: # db 연결 끊기
db.close()
conn.close()
if __name__ == '__main__': # 다른 파일에서 import해서 쓰지 않고 여기서 실행할 때만 실행되는 구문
# 질문/답변 학습 디비 연결 객체 생성
db = Database(
host=DB_HOST, user=DB_USER, password=DB_PASSWORD, db_name=DB_NAME
)
print("DB 접속")
port = 5050
listen = 100
# 봇 서버 동작
bot = BotServer(port, listen)
bot.create_sock()
print("bot start")
while True:
conn, addr = bot.ready_for_client()
params = {
"db": db
}
client = threading.Thread(target=to_client, args=(
conn,
addr,
params
))
client.start()
我尝试删除str对象,但结果没有改变。
下面是一条错误消息
文件“bot.py”,第17行,在
intent=IntentModel(model\u name='models/intent/intent\u model.h5',proprocess=p)文件
“/home/ubuntu/deepChatbot2/chatbot/models/intent/IntentModel.py”,第行
13,在init中
self.model=load\u model(model\u name)文件“/home/ubuntu/.local/lib/python3.6/site packages/tensorflow\u core/python/keras/saving/save.py”,
第146行,在load_模型中
返回hdf5\u格式。从\u hdf5(文件路径、自定义\u对象、编译)文件加载\u模型
“/home/ubuntu/.local/lib/python3.6/site packages/tensorflow\u core/python/keras/saving/hdf5\u format.py”,第166行,从hdf5加载模型
model_config=json.load(model_config.decode('utf-8'))AttributeError:'str'对象没有属性'decode'
谢谢。这是您的问题谢谢您让我知道,我尝试了h5py的较低版本,效果很好。这是您的问题谢谢您让我知道,我尝试了h5py的较低版本,效果很好。