synchronizing/mitm

Circular import error

Closed this issue · 4 comments

G'day!

I just got around to trying the 1.3.0 release. I created a fresh project on PyCharm, using Python 3.10 - When running the following code:

from mitm import MITM, CertificateAuthority, middleware, protocol
from pathlib import Path

# Loads the CA certificate.
path = Path("")
ca = CertificateAuthority.init(path=path)

# Starts the MITM server.
mitm = MITM(
    host="127.0.0.1",
    port=8888,
    protocols=[protocol.HTTP],
    middlewares=[middleware.Log],
    buffer_size=8192,
    timeout=5,
    ca=ca,
)
mitm.run()

It throws this error:

Traceback (most recent call last):
  File "/Users/myname/PycharmProjects/ComputerScience/misc/mitm.py", line 1, in <module>
    from mitm import CertificateAuthority, middleware, protocol
  File "/Users/myname/PycharmProjects/ComputerScience/misc/mitm.py", line 1, in <module>
    from mitm import CertificateAuthority, middleware, protocol
ImportError: cannot import name 'CertificateAuthority' from partially initialized module 'mitm' (most likely due to a circular import) (/Users/myname/PycharmProjects/ComputerScience/misc/mitm.py)

That's weird. Not getting that on my system with a fresh install of mitm. What Python version are you running?

Weird, but glad its working now 😄 . Closing this for now.