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.

Konrad
  • 6,385
  • 12
  • 53
  • 96
  • 1
    possible duplicate of [TypeError: 'str' does not support the buffer interface](http://stackoverflow.com/questions/5471158/typeerror-str-does-not-support-the-buffer-interface) – GolezTrol Jun 13 '15 at 08: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. – syntonym Jun 13 '15 at 08:21
  • @GolezTrol: there surely are better dupes than that. This is about literal values, not string data read from somewhere else. – Martijn Pieters Jun 13 '15 at 08:24

1 Answers1

3

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

unescaped = html.replace(rb'\""', b'"')
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343