label.replace() isn't unicode friendly, but re.sub() is, which is causing the error you're patching here. This whole section needs to be converted to use re.sub() like the rest