简体   繁体   English

python TypeError:强制转换为Unicode:需要字符串或缓冲区,找到NoneType

[英]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.

相关问题 Python:NoneType错误 - “强制转换为Unicode:需要字符串或缓冲区,找到NoneType” - Python: NoneType error - “coercing to Unicode: need string or buffer, NoneType found” TypeError:强制转换为Unicode,需要字符串或缓冲区,找到NoneType - TypeError: coercing to Unicode, need string or buffer, NoneType found TypeError:强制转换为Unicode:需要字符串或缓冲区,找不到NoneType - TypeError: coercing to Unicode: need string or buffer, NoneType found TypeError:强制转换为Unicode:需要字符串或缓冲区,找不到NoneType - TypeError: coercing to Unicode: need string or buffer, NoneType found Web爬网程序– TypeError:强制转换为Unicode:需要字符串或缓冲区,找不到NoneType - Web Crawler–––TypeError: coercing to Unicode: need string or buffer, NoneType found Python2.7 TypeError:强制转换为 Unicode:需要字符串或缓冲区,找到无类型 - Python2.7 TypeError: coercing to Unicode: need string or buffer, NoneType found TypeError:强制转换为Unicode:需要字符串或缓冲区,在python中找到文件 - TypeError: coercing to Unicode: need string or buffer, file found in python Python:TypeError:强制转换为Unicode:需要字符串或缓冲区,找到模块 - Python: TypeError: coercing to Unicode: need string or buffer, module found Python MQTT:TypeError:强制转换为Unicode:需要字符串或缓冲区,发现布尔 - Python MQTT: TypeError: coercing to Unicode: need string or buffer, bool found python 2.6 TypeError:强制转换为Unicode:需要字符串或缓冲区,找到列表 - python 2.6 TypeError: coercing to Unicode: need string or buffer, list found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM