/bin/sh: -c: line 0: unexpected EOF while looking for matching `''

I write a function in my script to look for a specific 'keyword' from a file (There are many of them) and return me the result if the keyword exists within this file.

def getRawData(self,mid): 
    self.output=[]
    List1= [s for s in self.MIDdict[mid] if 'HEX' in s]
    if len(List1)>0:
        for list in List1:
            with zipfile.ZipFile(self._LotDataFolder, 'r') as z:
                with z.open(list) as f1:
                    fi1 = f1.readlines()
                    assert (len(fi1) == 1),("The json output consist more than one line. Current script only support one output")
                    bist = json.loads(fi1[0])
                    firmware = bist['TST_VERSION']
                    list = bist['EventList']
                    if len(list)>0:
                        for num in xrange(len(list)):
                            temp= bist['EventList'][num]
                            if (args.grepString):
                                if temp['EventID'] in grepList:
                                    self.output.append([bist['MID'],self._density,self._ff,temp['EventID'],temp['TestID'], json.dumps(temp)])
                            else:
                                self.output.append([bist['MID'],self._density,self._ff,temp['EventID'],temp['TestID'], json.dumps(temp)])

        for sublist in self.output:
            print ("\t".join(map(str, sublist)))
    else:
        print mid +" does not contain event log"

I encountered this error while running the scripts

/bin/sh: -c: line 1: syntax error: unexpected end of file
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''

The problem that confuses me is, this error did not happen consistently. So, the scripts can run perfectly and return me the correct result on one file, but return me the above error message when running on other files.

**Note: I am using Python2.7 and running the scripts on Linux Server if that helps.