0

This may be a duplicate but I can't solve my problem. This line gives me the error

TypeError: 'str' does not support the buffer interface .

unescaped = html.replace(r'\""', '"')

Does it mean I have to write

unescaped = html.replace(bytes(r'\""', 'UTF-8'), bytes('"', 'UTF-8'))

Each time I need to replace a string?

Thank you in advance.

3
  • 1
    possible duplicate of TypeError: 'str' does not support the buffer interface Commented Jun 13, 2015 at 8:17
  • Where do you get the html from (and what encoding is it)? I would guess that you should decode the html, then replace (or do whatever you want with the html) and at the end, if you need it, encode it back to what encoding you need it to be. Commented Jun 13, 2015 at 8:21
  • @GolezTrol: there surely are better dupes than that. This is about literal values, not string data read from somewhere else. Commented Jun 13, 2015 at 8:24

1 Answer 1

3

You are using literal values so just use a bytes literal string, with a b prefix:

unescaped = html.replace(rb'\""', b'"')
Sign up to request clarification or add additional context in comments.

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.