1

I'm doing a curl request that returns something like this :

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

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. Doing this in Python

Rakesh
  • 78,594
  • 17
  • 67
  • 103
luc1
  • 13
  • 2

2 Answers2

2

If g is your binary string, g.decode("utf-8") will give you what you have asked.

RomanPerekhrest
  • 75,918
  • 4
  • 51
  • 91
LazyCoder
  • 1,167
  • 3
  • 17
1

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

s3nh
  • 526
  • 2
  • 11