TypeError: coercing to Unicode: need string or buffer, tuple found

bbruno5 picture bbruno5 · Aug 14, 2013 · Viewed 9.7k times · Source

I'm trying to make my app run files with Unicode characters, but for this, you must decode before them. For this I am using ConfigObj.py. But when I run the app, get the following error:

Traceback (most recent call last):
   File "GCW_Player.py", line 757, in <module>
     epMEDIA ()
   File "GCW_Player.py", line 89, in __ init__
     self.keyhandler (event.key)
   File "GCW_Player.py", line 133, in keyhandler
     if key == K_RIGHT: self.k_goto ()
   File "GCW_Player.py", line 211, in k_goto
     self.go_to ()
   File "GCW_Player.py", line 649, in go_to
     self.list.generate (self.sec_ftypes)
   File "/data/epm_core.py", line 114, in generate
     inp = os.listdir (self.path)
TypeError: coercing to Unicode: need string or buffer, tuple found

Below, let the corresponding part file in the app:

    def generate(self, filetypes):
        self.data = []
        inp = os.listdir(self.path)
        inp.sort()
        for line in inp:
            file = File(os.path.join(self.path, line), filetypes)
            if file.type != None:
                self.data.append(file)

Can anyone help me? I do not know what to do in this case. I've never experienced this situation. Thank you.

Answer

Your self.path contains multiple paths, maybe you need:

def generate(self, filetypes):
    self.data = []

    for folder in self.path:
        inp = os.listdir(folder)
        inp.sort()
        for line in inp:
            file = File(os.path.join(folder, line), filetypes)
            if file.type != None:
                self.data.append(file)