diff --git a/gruvi/jsonrpc.py b/gruvi/jsonrpc.py
index <HASH>..<HASH> 100644
--- a/gruvi/jsonrpc.py
+++ b/gruvi/jsonrpc.py
@@ -208,7 +208,7 @@ def create_error(request, code=None, message=None, data=None, error=None):
     """Create a JSON-RPC error response message."""
     if code is None and error is None:
         raise ValueError('either "code" or "error" must be set')
-    msg = {'id': request['id']}
+    msg = {'id': request and request.get('id')}
     if code:
         error = {'code': code}
         error['message'] = message or strerror(code)
[jsonrpc] create_error(): allow null id

This allows you to call create_error() with a message argument that is
either None, or a notification. The JSON-RPC spec allows erros with a
null ID in case it is not clear where the error belongs to.