Encode middleware error message as bytes

On py3 the middleware message needs to be passed as bytes instead of
string. Since on py2 str.encode() doesn't do anything it doesn't change
the behavior there.

Change-Id: Ie593e8659be736aa4d85ca2a47ae2a30db446f84
Closes-Bug: 1372484