def dummy_send_gradient_update(self):
        message = create_gradient_message(self.net)
        p = np.random.rand()
        if p < 0.98:
            response = "OK"
        else:
            response = "ERROR"

        return response
    def send_gradient_update(self):
        """ Sends message as HTTP request; blocks until response is received.
        Raises URLError if cannot be reach driver.
        """
        if self.driver is None:
            return self.dummy_send_gradient_update()

        message = create_gradient_message(self.net)
        try:
            request = urllib2.Request(
                'http://%s/api/v1/update_model' % self.driver,
                headers={'Content-Type': 'application/deepQ'},
                data=message)
            response = urllib2.urlopen(request).read()
        except urllib2.URLError as e:
            print e.message
            raise

        return response