简体   繁体   中英

python TypeError: coercing to Unicode: need string or buffer, NoneType found

I have been attempting to use a python program called chatbot1.5.2b. It is designed to work on 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):

  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. 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.

Here is the code for the area around line 348 in chatbot.py:

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.

You can't convert a None to a unicode value.

This is what you need to do

add this line before 348

room = str(settings['room']) if str(settings['room']) == None else ''

replace line 348 with this

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM