Ensure that identity request variables are UTF-8 encoded

It is critical that the server recieves UTF-8 encoded strings and not
`unicode` instances.  Passing such instances blindly to the `str()`
constructor will result in a `UnicodeDecodeError` being raised.
Test case for proper unicode encoding when using gateway
Fix flake8 errors
Merge pull request #2994 from chris-allan/fix-password-encoding

Ensure that identity request variables are UTF-8 encoded