[英]python TypeError: coercing to Unicode: need string or buffer, NoneType found
I have been attempting to use a python program called chatbot1.5.2b. 我一直在尝试使用一个名为chatbot1.5.2b的python程序。 It is designed to work on Wikia.
它旨在在Wikia上工作。 However, after following all the steps, I come across this error when I run the startup script:
但是,按照所有步骤操作后,运行启动脚本时会遇到此错误:
Exception in thread Thread-1: Traceback (most recent call last):
线程Thread-1中的异常:回溯(最近一次调用为last):
File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\Python27\lib\site-packages\chatbot.py", line 405, in run
connect = self.c.connection()
File "C:\Python27\lib\site-packages\chatbot.py", line 361, in connection
var = self.__connection(self.settings, self.xhr)
File "C:\Python27\lib\site-packages\chatbot.py", line 348, in __connection
str(settings['room']) + "&t=" +
TypeError: coercing to Unicode: need string or buffer, NoneType found
I am using Python 2.7.8. 我正在使用Python 2.7.8。 I have read several other questions on here on very similar topics, but if I try and follow them, such as by putting
str()
around the "&t="
, it gives exactly the same error, except that it displays the code with str("&t=")
instead. 我在这里已经阅读了关于非常相似主题的其他几个问题,但是如果我尝试并遵循它们,例如通过将
str()
放在"&t="
周围,则会给出完全相同的错误,不同之处在于它将显示带有str("&t=")
的代码str("&t=")
代替。
Here is the code for the area around line 348 in chatbot.py: 这是chatbot.py中第348行周围区域的代码:
data = self.session.get("http://" + settings["host"] + ":" +
settings["port"] +
"/socket.io/1/xhr-polling/" + xhr_polling
+ "?name=" + self.username + "&key=" +
settings['chatkey'] + "&roomId=" +
str(settings['room']) + "&t=" +
time)
content = re.findall(r'.:::(.*)', data.content.decode('utf8'))
Any help greatly appreciated. 任何帮助,不胜感激。 I'm not very familiar with Python, so I might be doing something really stupid.
我对Python不太熟悉,所以我可能做的事情确实很愚蠢。
You can't convert a None to a unicode value. 您不能将None转换为unicode值。
This is what you need to do 这就是你要做的
add this line before 348 在348之前添加此行
room = str(settings['room']) if str(settings['room']) == None else ''
replace line 348 with this 替换348行与此
data = self.session.get("http://{host}:{port}/socket.io/1/xhr-polling/{polling}?name={username}&key={chatkey}&roomId={room}&t={time}".format(host=settings["host"],port=settings["port"],polling=xhr_polling,username=self.username,chatkey=settings["chatkey"],room=room,time=time))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.