# Buggy code
def send_vip_object(self, message):
    """
    Send the VIP message over RabbitMQ message bus.
    Reformat the VIP message object into Pika message object and
    publish it using Pika library
    :param message: VIP message object
    :return:
    """
    platform = getattr(message, "platform", self._instance_name)
    if message.peer == b"":
        message.peer = "router"
    if platform == b"":
        platform = self._instance_name

    destination_routing_key = "{0}.{1}".format(platform, message.peer)

    # Fit VIP frames in the PIKA properties dict
    # VIP format - [SENDER, RECIPIENT, PROTO, USER_ID, MSG_ID, SUBSYS, ARGS...]
    dct = {
        "user_id": self._rmq_userid,
        "app_id": self.routing_key,  # Routing key of SENDER
        "headers": dict(
            recipient=destination_routing_key,  # RECEIVER
            proto=b"VIP",  # PROTO
            user=getattr(message, "user", self._rmq_userid),  # USER_ID
        ),
        "message_id": getattr(message, "id", b""),  # MSG_ID
        "type": message.subsystem,  # SUBSYS
        "content_type": "application/json",
    }
    properties = pika.BasicProperties(**dct)
    msg = getattr(message, "args", None)  # ARGS
    # _log.debug("PUBLISHING TO CHANNEL {0}, {1}, {2}, {3}".format(destination_routing_key,
    #                                                              msg,
    #                                                              properties,
    #                                                              self.routing_key))
    try:
        self.channel.basic_publish(
            self.exchange,
            destination_routing_key,
            json.dumps(msg, ensure_ascii=False),
            properties,
        )
    except (
        pika.exceptions.AMQPConnectionErro,
        pika.exceptions.AMQPChannelError,
    ) as exc:
        raise Unreachable(
            errno.EHOSTUNREACH,
            "Connection to RabbitMQ is lost",
            "rabbitmq broker",
            "rmq_connection",
        )


# Traceback (AttributeError)
Shutting down VOLTTRON
Traceback (most recent call last):
File "/home/osboxes/repos/pr-test/env/local/lib/python2.7/site-packages/gevent/greenlet.py", line 534, in run
result = self._run(*self.args, **self.kwargs)
File "/home/osboxes/repos/pr-test/volttron/platform/vip/agent/core.py", line 276, in run
looper.next()
File "/home/osboxes/repos/pr-test/volttron/platform/vip/agent/core.py", line 888, in loop
param = self._build_connection_parameters()
File "/home/osboxes/repos/pr-test/volttron/platform/vip/agent/core.py", line 883, in _build_connection_parameters
self.instance_name)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 876, in build_agent_connection
self.create_user_with_permissions(rmq_user, permissions, ssl_auth=self.is_ssl)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 847, in create_user_with_permissions
if user not in self.get_users(ssl_auth):
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 248, in get_users
response = self._http_get_request(url, ssl_auth)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 163, in _http_get_request
response = self._call_grequest('get', url, ssl_auth)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 116, in _call_grequest
raise e
AttributeError: 'NoneType' object has no attribute 'raise_for_status'
<Greenlet at 0x7ff71ca50eb0: <bound method RMQCore.run of <volttron.platform.vip.agent.core.RMQCore object at 0x7ff71c976f50>>(<gevent.event.Event object at 0x7ff71c9685d0>)> failed with AttributeError

# Fixed code
def send_vip_object(self, message):
    """
    Send the VIP message over RabbitMQ message bus.
    Reformat the VIP message object into Pika message object and
    publish it using Pika library
    :param message: VIP message object
    :return:
    """
    platform = getattr(message, "platform", self._instance_name)
    if message.peer == b"":
        message.peer = "router"
    if platform == b"":
        platform = self._instance_name

    destination_routing_key = "{0}.{1}".format(platform, message.peer)

    # Fit VIP frames in the PIKA properties dict
    # VIP format - [SENDER, RECIPIENT, PROTO, USER_ID, MSG_ID, SUBSYS, ARGS...]
    dct = {
        "user_id": self._rmq_userid,
        "app_id": self.routing_key,  # Routing key of SENDER
        "headers": dict(
            recipient=destination_routing_key,  # RECEIVER
            proto=b"VIP",  # PROTO
            user=getattr(message, "user", self._rmq_userid),  # USER_ID
        ),
        "message_id": getattr(message, "id", b""),  # MSG_ID
        "type": message.subsystem,  # SUBSYS
        "content_type": "application/json",
    }
    properties = pika.BasicProperties(**dct)
    msg = getattr(message, "args", None)  # ARGS
    # _log.debug("PUBLISHING TO CHANNEL {0}, {1}, {2}, {3}".format(destination_routing_key,
    #                                                              msg,
    #                                                              properties,
    #                                                              self.routing_key))
    try:
        self.channel.basic_publish(
            self.exchange,
            destination_routing_key,
            json.dumps(msg, ensure_ascii=False),
            properties,
        )
    except (
        pika.exceptions.AMQPConnectionError,
        pika.exceptions.AMQPChannelError,
    ) as exc:
        raise Unreachable(
            errno.EHOSTUNREACH,
            "Connection to RabbitMQ is lost",
            "rabbitmq broker",
            "rmq_connection",
        )