PythonDMARCDockerDMARCvisualizermsgraph

dmarc-visualizer を起動後 ModuleNotFoundError: No module named 'msgraph' が出て動かない時にすること

はじめに

dmarc-visualizer を利用し DMARC レポートの集計を試みた。 諸々の設定が完了し起動してみたが ModuleNotFoundError: No module named 'msgraph' が発生し、dmarc-visualizer を起動できなかった。原因が分かったので回避策と理由を書き残しておきます。

出力されたエラー

dmarc-visualizer を起動すると下記エラーで終了してしまう。

Traceback (most recent call last):
  File "/usr/local/bin/parsedmarc", line 5, in <module>
    from parsedmarc.cli import _main
  File "/usr/local/lib/python3.9/site-packages/parsedmarc/__init__.py", line 31, in <module>
    from parsedmarc.mail import MailboxConnection
  File "/usr/local/lib/python3.9/site-packages/parsedmarc/mail/__init__.py", line 2, in <module>
    from parsedmarc.mail.graph import MSGraphConnection
  File "/usr/local/lib/python3.9/site-packages/parsedmarc/mail/graph.py", line 10, in <module>
    from msgraph.core import GraphClient
ModuleNotFoundError: No module named 'msgraph'

変更箇所

:::note warn この修正方法は、dmarc-visualizer671b16a に有効であった。その他バージョン? コミットでは検証していない。 :::

diff --git a/parsedmarc/Dockerfile b/parsedmarc/Dockerfile
index c2ea0cd..bfb5391 100644
--- a/parsedmarc/Dockerfile
+++ b/parsedmarc/Dockerfile
@@ -2,7 +2,7 @@ FROM python:3.9-alpine3.16

 RUN apk add --update --no-cache libxml2-dev libxslt-dev
 RUN apk add --update --no-cache --virtual .build_deps build-base libffi-dev \
-    && pip install parsedmarc \
+    && pip install parsedmarc msgraph-core==0.2.2 \
     && apk del .build_deps

 COPY parsedmarc.ini

変更の理由・背景

dmarc-visualizer は、 parsedmarcElasticsearchGrafana を利用している。 今回出ていたエラーは parsedmarc で発生している。 parsedmarc のレポジトリを確認したところすでに Issue が作成されていた。

I looked up the module name msgraph and found that it refers to the dependent package msgraph-core, The latest version of msgraph-core, 1.0.0, was released on 2024-01-23, the first major release since 2021-07-27.

On the other hand, if you look at project.toml, you will see that >= 0.2.2.

# Line 50 in 7d2b431
"msgraph-core>=0.2.2",

Therefore, it is assumed that a new installation of parsedmarc installs msgraph-core 1.0.0, and that it no longer works.

簡単に書くと .... 原因は module 'msgraph' の依存元である msgraph-core のメジャーリリースが2024年1月に行われた。parsedmarc の project.toml の定義では v0.2 ではなく、新しい v1 が取得されてしまい起動に失敗した。 ただ、原因はわかりましたが dmarc-visualizer に存在しない project.toml を編集することが不可能だったため parsedmarc/Dockerfile を編集することとした。

References