我正在执行一个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做到这一点
答案 0 :(得分:1)
如果g
是您的二进制字符串,则g.decode("utf-8")
会给您您所要的内容。
答案 1 :(得分:0)
我认为您应该尝试
# 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')