can';t通过正则表达式从python3中的字节中删除字符串

can';t通过正则表达式从python3中的字节中删除字符串,python,regex,tornado,python-3.4,Python,Regex,Tornado,Python 3.4,*我在Python3中使用re.sub时出错 **我的代码是: chunk = re.sub(b'-----------------------------(.+)--\r\n', '', chunk 我有一个错误: Type Error: sequence item 0: `expected` a bytes-like object, str found 它在python2中工作,但在python3.4中不工作。 除此之外,我还使用了龙卷风 请帮我解决这个问题。替换部件也必须是字

*我在Python3中使用re.sub时出错 **我的代码是:

 chunk = re.sub(b'-----------------------------(.+)--\r\n', '', chunk 
我有一个错误:

   Type Error: sequence item 0: `expected` a bytes-like object, str found
它在python2中工作,但在python3.4中不工作。 除此之外,我还使用了龙卷风
请帮我解决这个问题。

替换部件也必须是字节字符串

chunk = re.sub(b'-----------------------------(.+)--\r\n', b'', chunk)
例如:

>>> chunk = b'-----------------------------5313032314004\r\nContent-Disposition: form-data; name="file"; filename="4.jpg"\r\nContent-Type: image/jpeg\r\n\r\n\xff\xd8\xff'
>>> re.sub(b'-', b'', chunk)
b'5313032314004\r\nContentDisposition: formdata; name="file"; filename="4.jpg"\r\nContentType: image/jpeg\r\n\r\n\xff\xd8\xff'

不当我在字符串之前使用r时,会出现以下错误:::无法在objectchunk=b'-------------------------------5313032314004\r\n内容配置:表单数据;name=“file”;filename=“4.jpg”\r\n内容类型:image/jpeg\r\n\r\n\xff\xd8\xff\…执行此操作,然后我尝试从ITE中删除'-------------5313032514004\r\n实际上,chunk是文件的一部分,我是通过Ajax@seydimanfeyzbakhsh替换部件必须是字节字符串。检查我的更新。@Avinash Raj:我尝试了b'----…',但不起作用。