程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了python3 对 <class 'bytes'> 类型的 post_body 执行 re.sub?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决python3 对 <class 'bytes'> 类型的 posT_Body 执行 re.sub??

开发过程中遇到python3 对 <class 'bytes'> 类型的 posT_Body 执行 re.sub?的问题如何解决?下面主要结合日常开发的经验,给出你关于python3 对 <class 'bytes'> 类型的 posT_Body 执行 re.sub?的解决方法建议,希望对你解决python3 对 <class 'bytes'> 类型的 posT_Body 执行 re.sub?有所启发或帮助;

Json.loads(posT_Body) 得到了 在那里我可以看到 Json/text 中 Json.loads(posT_Body) 的内容。 问题是如何更新 posT_Body 以屏蔽/替换一些 Json/text 并将其转换回原始 ? 我想实现注释行,但没有获得 "TypeError: a bytes-like object is required,not 'str'" 目标是让 posT_Body 没有实际的 pwd=secret 和 password=secret 信息,但被 xx 取代 请指教。谢谢。

            self.server.logger.info(Json.loads(posT_Body))

            #if "password" in Json.loads(posT_Body):
            # posT_Body = re.sub(r"(.*)(pwd=)([a-z,A-Z,0-9]+)(\",\s+)(\"password\":\s+\")(\w+)(.*)",r"\1\2xx\4\5xx\7",str(Json.load(posT_Body))) ???
             
            # Send Event to Splunk via event_writer
            self.server.output_results(Json.loads(posT_Body),self.client_address[0])
    
@H_673_13@ 

解决方法

想出了以下内容:

            self.server.logger.info(json.loads(posT_Body))

            if "password" in posT_Body.decode("utf-8"):
              posT_Body_d = re.sub(r"(.*)(pwd=)([a-z,A-Z,0-9]+)(\",\s+)(\"password\":\s+\")(\w+)(.*)",r"\1\2xx\4\5xx\7",posT_Body.decode("utf-8"))
              posT_Body = posT_Body_d.encode("utf-8")
            # Send Event to Splunk via event_writer
            self.server.output_results(json.loads(posT_Body),self.client_address[0])
@H_673_13@

大佬总结

以上是大佬教程为你收集整理的python3 对 <class 'bytes'> 类型的 post_body 执行 re.sub?全部内容,希望文章能够帮你解决python3 对 <class 'bytes'> 类型的 post_body 执行 re.sub?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。