繁体   English   中英

如何将输出从curl转换为字符串对象

[英]How to convert an output from a curl into a string object

我正在做一个curl请求,返回的内容是这样的:

b'{\n  "output": {\n    id": "11-222-33-44-5abcd6efg"\n  }\n}\n'

然后我在做

id=re.sub("\{.*\: \"", "", output)
id=re.sub("\" *\}.*", "", id)

但我得到:TypeError:不能在类似字节的对象上使用字符串模式

我想将输出转换为字符串,然后可能会起作用,或者,如果您有任何其他想法,我的目标是获取该ID。 用Python做到这一点

如果g是您的二进制字符串,则g.decode("utf-8")将为您提供所要的内容。

我认为,您应该尝试


# utf-8 is used here because it is a very common encoding, but you
# need to use the encoding your data is actually in.

output = output.decode('utf-8')

类似问题的解决方案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM