So is it working at all?
In Mathematica:
In[88]:= MultiplicativeOrder[3, 401, 138]
Out[88]= 318
In SageMath 9.4:
discrete_log(138, 3, 401-1)
...
"ValueError: No discrete log of 138 found to base 3"
I tried 401 and operation="*"
What I want? I want 318, because, in Python:
pow(3,318,401)=138