circular import? Different in python call and python IDLE
relaxtheo opened this issue · 1 comments
I have a very simple test program,sd1.py, just follow the web page. I run it by python3 sd1.py, and get a circular import error. However, if I run it in python3 console line by line, it will get other problem(mostly my camera problem).
What's the problem?
- Run by python3 sd1.py
xxxx@ub20base:~/WS/ircm$ cat sd1.py
from sensecam_discovery import Camera
ip='192.168.0.202'
user='admin'
password='admin123'
camera = Camera(ip, user, password)
print(camera)
xxxx@ub20base:~/WS/ircm$ python3 sd1.py
Traceback (most recent call last):
File "sd1.py", line 1, in
from sensecam_discovery import Camera
File "/home/xxxx/.local/lib/python3.8/site-packages/sensecam_discovery/init.py", line 5, in
from sensecam_discovery.Camera import Camera, CameraError
File "/home/xxxx/.local/lib/python3.8/site-packages/sensecam_discovery/Camera.py", line 4, in
from onvif import ONVIFCamera
File "/home/xxxx/WS/ircm/onvif.py", line 11, in
from sensecam_discovery.Camera import Camera
ImportError: cannot import name 'Camera' from partially initialized module 'sensecam_discovery.Camera' (most likely due to a circular import) (/home/xxxx/.local/lib/python3.8/site-packages/sensecam_discovery/Camera.py)
xxxx@ub20base:~/WS/ircm$
Run in python3 console:
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
from sensecam_discovery import Camera
ip='192.168.0.202'
user='admin'
password='admin123'
camera = Camera(ip, user, password)
Traceback (most recent call last):
File "/home/xxxx/.local/lib/python3.8/site-packages/onvif/client.py", line 23, in wrapped
return func(*args, **kwargs)
File "/home/xxxx/.local/lib/python3.8/site-packages/onvif/client.py", line 153, in wrapped
return call(params, callback)
File "/home/xxxx/.local/lib/python3.8/site-packages/onvif/client.py", line 140, in call
ret = func(**params)
File "/home/xxxx/.local/lib/python3.8/site-packages/zeep/proxy.py", line 46, in call
return self._proxy._binding.send(
File "/home/xxxx/.local/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 135, in send
return self.process_reply(client, operation_obj, response)
File "/home/xxxx/.local/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 229, in process_reply
return self.process_error(doc, operation)
File "/home/xxxx/.local/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 352, in process_error
raise Fault(
zeep.exceptions.Fault: Unknown fault occured
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/xxxx/.local/lib/python3.8/site-packages/sensecam_discovery/Camera.py", line 26, in init
self._mycam = ONVIFCamera(ip, 80, user, password, no_cache = True)
File "/home/xxxx/.local/lib/python3.8/site-packages/onvif/client.py", line 216, in init
self.update_xaddrs()
File "/home/xxxx/.local/lib/python3.8/site-packages/onvif/client.py", line 233, in update_xaddrs
capabilities = self.devicemgmt.GetCapabilities({'Category': 'All'})
File "/home/xxxx/.local/lib/python3.8/site-packages/onvif/client.py", line 26, in wrapped
raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Unknown fault occured
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/home/xxxx/.local/lib/python3.8/site-packages/sensecam_discovery/Camera.py", line 28, in init
raise CameraError("Could not connect to camera. Verify credentials and ONVIF support.")
sensecam_discovery.Camera.CameraError: Could not connect to camera. Verify credentials and ONVIF support.
The problem disappear