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 #3047 from sbesson/rebased/dev_5_0/fix-password-encoding

Ensure that identity request variables are UTF-8 encoded (rebased onto dev_5_0)