Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Check that arguments and keyword arguments are not passed simultaneously in jsonrpc_client_call()

Pablo Hoffman88c99e0b838a
diff --git a/scrapy/tests/test_utils_jsonrpc.py b/scrapy/tests/test_utils_jsonrpc.py
index f8f8b13fb..fe62fb319 100644
--- a/scrapy/tests/test_utils_jsonrpc.py
+++ b/scrapy/tests/test_utils_jsonrpc.py
@@ -36,6 +36,9 @@ class JsonRpcUtilsTestCase(unittest.TestCase):
crawler = CrawlerMock([])
self.json_decoder = ScrapyJSONDecoder(crawler=crawler)
+ def test_jsonrpc_client_call_args_kwargs_raises(self):
+ self.assertRaises(ValueError, jsonrpc_client_call, 'url', 'test', 'one', kw=123)
+
def test_jsonrpc_client_call_request(self):
ul = urllib_mock(1)
jsonrpc_client_call('url', 'test', 'one', 2, _urllib=ul)
diff --git a/scrapy/utils/jsonrpc.py b/scrapy/utils/jsonrpc.py
index d9d4008c9..686a1d235 100644
--- a/scrapy/utils/jsonrpc.py
+++ b/scrapy/utils/jsonrpc.py
@@ -31,6 +31,8 @@ class JsonRpcError(Exception):
def jsonrpc_client_call(url, method, *args, **kwargs):
"""Execute a JSON-RPC call on the given url"""
_urllib = kwargs.pop('_urllib', urllib)
+ if args and kwargs:
+ raise ValueError("Pass *args or **kwargs but not both to jsonrpc_client_call")
req = {'jsonrpc': '2.0', 'method': method, 'params': args or kwargs, 'id': 1}
res = json.loads(_urllib.urlopen(url, json.dumps(req)).read())
if 'result' in res: