Errors Returned While Using 'update_server'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 491
- Forks
- 290
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 3
Description
Hey team,
Apologise in advance if I've made a dumb/simple mistake here, but I seem to be have encountered an error with PyMISP's 'update_server' function that I haven't been able to troubleshoot my way through.
Attempts to execute the following code (simplified version that still returns same error shown below) has been giving me the subsequent error:
CODE
misp = PyMISP(url=url, key=api_key, ssl=verify)
server = MISPServer()
server.name = "test"
misp.update_server(server, 2)
ERROR
Unknown error: the response is not in JSON.
Something is broken server-side, please send us everything that follows (careful with the auth key):
Request headers:
{'User-Agent': 'PyMISP 2.4.160.1 - Python 3.8', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json', 'Connection': 'keep-alive', 'Cookie': 'MISP-49b47302-f263-49d7-959b-ad34c8adf7bf=f5tuu4qe0csiq748f5jq42g74qvdnke3', 'Content-Length': '16', 'content-type': 'application/json'}
Request body:
{"name": "test"}
Response (if any):
{"name":"An Internal Error Has Occurred.","message":"An Internal Error Has Occurred.","url":"/servers/edit/2"}
Traceback (most recent call last):
File "getsync.py", line 15, in
misp.update_server(server, 2)
File "/home/appadmin/.local/lib/python3.8/site-packages/pymisp/api.py", line 1862, in update_server
updated_server = self._check_json_response(r)
File "/home/appadmin/.local/lib/python3.8/site-packages/pymisp/api.py", line 3513, in _check_json_response
r = self._check_response(response, expect_json=True)
File "/home/appadmin/.local/lib/python3.8/site-packages/pymisp/api.py", line 3531, in _check_response
raise MISPServerError(f'Error code 500:\n{response.text}')
pymisp.exceptions.MISPServerError: Error code 500:
{"name":"An Internal Error Has Occurred.","message":"An Internal Error Has Occurred.","url":"/servers/edit/2"}
I've also reviewed my servers error.log which contains the following indicating a potential JSON syntax issue:
2022-09-21 04:41:49 Error: [JsonException] Syntax error
Request URL: /servers/edit/2
Stack Trace:
#0 /var/www/MISP/app/Lib/Tools/JsonTool.php(31): json_decode()
#1 /var/www/MISP/app/Model/AppModel.php(3552): JsonTool::decode()
#2 /var/www/MISP/app/Controller/ServersController.php(506): AppModel->jsonDecode()
#3 [internal function]: ServersController->edit()
#4 /var/www/MISP/app/Lib/cakephp/lib/Cake/Controller/Controller.php(499): ReflectionMethod->invokeArgs()
#5 /var/www/MISP/app/Lib/cakephp/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction()
#6 /var/www/MISP/app/Lib/cakephp/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke()
#7 /var/www/MISP/app/webroot/index.php(99): Dispatcher->dispatch()
#8 {main}
root@host:/home/user# 2022-09-21 04:41:49 Error: [JsonException] Syntax error
#5 /var/www/MISP/app/Lib/cakephp/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction()
#6 /var/www/MISP/app/Lib/cakephp/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke()
#7 /var/www/MISP/app/webroot/index.php(99): Dispatcher->dispatch()
#8 {main}
In terms of troubleshooting I've ensured my API key is correct, the URL is accessible, updated MISP and PyMISP (note - still seems to be out of date when upgrading with pip), and experimented with modifications to my code.
Please let me know if this is a extremely beginner mistake or if I've missed something in the documentation, any assistance is greatly appreciated.
Edit: Looks like it could be an issue with MISP itself. Attempts to use the API for the /server/update/X endpoint seem to be failing with the same error, while other endpoints such as /server/add are working as expected.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pymisp/api.py at update_server and _check_json_response, then compare the request sent to /servers/edit/2 with the working /server/add endpoint. Use the MISP stack trace locations—JsonTool.php, AppModel.php, and ServersController.php—to isolate the 500 response; done means the update endpoint accepts the request and returns valid JSON without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100