If you want an `unicode` object as input, it doesn't have any encoding. I'd remove this line and add an `.encode()` call in the function body:

```
xml_bytes = xml.encode(encoding)
return etree.tostring(etree.fromstring(xml_bytes),
                      pretty_print=True,
                      xml_declaration=xml_declaration,
                      encoding=encoding)
```