Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions misp_modules/modules/expansion/vysion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import logging
from urllib.parse import urlparse

import vysion.client as vysion
import vysion.dto
from pymisp import MISPAttribute, MISPEvent
from vysion.dto.util import MISPProcessor

from . import standard_error_message

Expand Down Expand Up @@ -66,6 +63,26 @@
DEFAULT_RESULTS_LIMIT = 10


def _load_vysion_dependencies():
"""Load Vysion runtime dependencies lazily.

Some transitive Vysion dependencies currently fail to import on newer
Python versions (3.13/3.14). Delaying the import avoids breaking module
registration and allows returning a controlled runtime error instead.
"""
try:
import vysion.client as vysion # type: ignore
from vysion.dto.util import MISPProcessor # type: ignore
except Exception as exc:
raise RuntimeError(
"Vysion dependencies could not be imported. "
"Please upgrade the 'vysion' and 'softenum' packages to versions "
"compatible with your Python runtime."
) from exc

return vysion, MISPProcessor


def get_proxy_settings(config: dict) -> dict:
"""Returns proxy settings in the requests format.
If no proxy settings are set, return None."""
Expand Down Expand Up @@ -136,6 +153,7 @@ def handler(q=False):
proxy_settings = get_proxy_settings(request.get("config"))

try:
vysion, MISPProcessor = _load_vysion_dependencies()

client = vysion.Client(
api_key=request["config"]["apikey"],
Expand Down Expand Up @@ -196,12 +214,21 @@ def handler(q=False):
}
}

except vysion.APIError as ex:
except RuntimeError as ex:
LOGGER.error("Error loading Vysion dependencies")
LOGGER.error(ex)
misperrors["error"] = str(ex)
return misperrors

except Exception as ex:

LOGGER.error("Error in Vysion")
LOGGER.error(ex)

misperrors["error"] = ex.message
if hasattr(ex, "message"):
misperrors["error"] = ex.message
else:
misperrors["error"] = str(ex)
return misperrors


Expand Down
Loading