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
  • 81,458
  • 17
  • 76
  • 113
luc1
  • 13
  • 2

2 Answers2

2

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

RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
LazyCoder
  • 1,267
  • 5
  • 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
  • 546
  • 2
  • 11