The check for str type is just in case, in the future, somebody reconfigures the socket to return error codes rather than raise errors.