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

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