简体   繁体   English

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

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

I'm doing a curl request that returns something like this : 我正在做一个curl请求,返回的内容是这样的:

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

then I'm doing 然后我在做

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

but i get : TypeError: can't use a string pattern on a bytes-like object 但我得到:TypeError:不能在类似字节的对象上使用字符串模式

I'd like to convert the output into string maybe it would work then, or if you have any other idea, my goal is to get that id. 我想将输出转换为字符串,然后可能会起作用,或者,如果您有任何其他想法,我的目标是获取该ID。 Doing this in Python 用Python做到这一点

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

In my opinion, you should try 我认为,您应该尝试


# 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')

Similar problem solution 类似问题的解决方案

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

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