Форум сайта python.su
31
Работал без проблем бот, и стал выдавать ошибку
# -*- coding: utf-8 -*-
import sys
import xmpp
##########function
def runPlugin(command,bot,mess):
plugin = getattr(bot.plugins['plugins'],command)
plugin.run(bot,mess)
def loadPlugins():
import os
commands = []
public_commands = []
for fname in os.listdir('plugins/'):
if fname.endswith('.py'):
plugin_name = fname[:-3]
if plugin_name != '__init__':
plugins = __import__('plugins.'+plugin_name)
plugin = getattr(plugins,plugin_name)
if plugin.init():
commands.append(plugin_name)
else:
public_commands.append(plugin_name)
return {'plugins':plugins,'commands':commands,'public_commands':public_commands}
def loadConfig():
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.ini')
login = config.get('connect', 'login')
password = config.get('connect', 'password')
allow_password = config.get('permission', 'allow_password')
user_no_pass = config.get('permission', 'user_no_pass')
user_no_pass = user_no_pass.split(',')
return {'login' : login, 'password' : password, 'allow_password' : allow_password, 'user_no_pass' : user_no_pass }
def message(conn,mess):
global bot
text = mess.getBody()
if ( text == None ):
return
command = text.split(' ')
command = command[0]
if command in bot.plugins['public_commands']:
runPlugin(command,bot,mess)
return
user=mess.getFrom()
user=str(user).split('/')
user=user[0]
if user not in bot.config['user_no_pass']:
text = "wrong command. try 'help'"
bot.send(xmpp.Message(mess.getFrom(),text))
return
if command in bot.plugins['commands']:
runPlugin(command,bot,mess)
else:
text = "wrong command. try 'help'"
bot.send(xmpp.Message(mess.getFrom(),text))
return
##########
config = loadConfig()
jid = xmpp.JID(config['login'])
bot = xmpp.Client(jid.getDomain(),debug=[])
bot.config = config
bot.plugins = loadPlugins()
conres=bot.connect()
if not conres:
print "Unable to connect to server!"
sys.exit(1)
authres=bot.auth(jid.getNode(),bot.config['password'])
if not authres:
print "Unable to authorize - check login/password"
sys.exit(1)
bot.RegisterHandler('message',message)
bot.sendInitPresence()
print "Bot started"
bot.online = 1
while bot.online:
bot.Process(1)
bot.disconnect()
print "Bot stoped"
Traceback (most recent call last):
File "D:\bot\bot\bot.py", line 87, in <module>
bot.Process(1)
File "D:\bot\bot\xmpp\dispatcher.py", line 303, in dispatch
handler['func'](session,stanza)
File "D:\bot\bot\bot.py", line 47, in message
runPlugin(command,bot,mess)
File "D:\bot\bot\bot.py", line 9, in runPlugin
plugin.run(bot,mess)
File "D:\bot\bot\plugins\pass.py", line 9, in run
user=str(user).split('/')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 23-29: ordinal not in range(128)
>>>
Отредактировано sanodin (Окт. 1, 2012 20:12:46)
Офлайн
14
Я так понимаю, ошибка в str(user). Что такое user? Какая версия питона?
Отредактировано odnochlen (Окт. 1, 2012 20:32:00)
Офлайн
31
odnochlen
Я так понимаю, ошибка в str(user). Что такое user? Какая версия питона?
# -*- coding: utf-8 -*-
import xmpp
def init():
return 0
def run(bot,mess):
user=mess.getFrom()
user=str(user).split('/')
user=user[0]
text = mess.getBody()
if text == 'pass '+bot.config['allow_password']:
bot.config['user_no_pass'].append(user)
text = 'password right'
bot.send(xmpp.Message(mess.getFrom(),text))
else:
text = 'password wrong'
bot.send(xmpp.Message(mess.getFrom(),text))
[connect]
login = xxxxxxx@jabber.ru
password = 123
[permission]
allow_password = 123
user_no_pass =
Отредактировано sanodin (Окт. 1, 2012 20:50:17)
Офлайн
31
Все решилось перезагрузкой удаленного компьютера…хз что было
Офлайн
14
Еще ничего не решилось. Ошибка у тебя есть, просто она не проявляется.
Офлайн
31
odnochlen
Еще ничего не решилось. Ошибка у тебя есть, просто она не проявляется.
Офлайн