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

0

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.