FalkTannhaeuser / python-onvif-zeep

ONVIF Client Implementation in Python 2+3 (using https://github.com/mvantellingen/python-zeep instead of suds as SOAP client)
MIT License
424 stars 138 forks source link

sqlite3 dependency within zeep causes an error if a cacheless Transport is not specified #35

Open monocongo opened 5 years ago

monocongo commented 5 years ago

I am attempting to use the package as described in the README, e.g. creating an ONVIFCamera instance for later use to access related ONVIF services. My code looks like this:

    camera = ONVIFCamera(host='123.45.6.78',
                         port=80,
                         user='bugs',
                         passwd='bunny',
                         wsdl_dir='..\wsdl')
    result = camera.CreatePullPointSubscription()```

There appears to be a missing sqlite3 module dependency as shown in the below error:

C:\home\miniconda\envs\scw\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 57125 --file C:/home/git/onvif_interact/scripts/poll_notifications_pull_point.py
pydev debugger: process 14968 is connecting

Connected to pydev debugger (build 183.5429.31)
Traceback (most recent call last):
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 23, in wrapped
    return func(*args, **kwargs)
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 102, in __init__
    self.zeep_client = ClientType(wsdl=url, wsse=wsse, transport=transport, settings=settings)
  File "C:\home\miniconda\envs\scw\lib\site-packages\zeep\client.py", line 211, in __init__
    kwargs.get('transport') or Transport(cache=SqliteCache()))
  File "C:\home\miniconda\envs\scw\lib\site-packages\zeep\cache.py", line 67, in __init__
    raise RuntimeError("sqlite3 module is required for the SqliteCache")
RuntimeError: sqlite3 module is required for the SqliteCache

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/home/git/onvif_interact/scripts/poll_notifications_pull_point.py", line 17, in <module>
    main()
  File "C:/home/git/onvif_interact/scripts/poll_notifications_pull_point.py", line 10, in main
    wsdl_dir='../wsdl')
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 216, in __init__
    self.update_xaddrs()
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 223, in update_xaddrs
    self.devicemgmt  = self.create_devicemgmt_service()
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 333, in create_devicemgmt_service
    return self.create_onvif_service('devicemgmt', from_template)
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 321, in create_onvif_service
    transport=self.transport)
  File "C:\home\miniconda\envs\scw\lib\site-packages\onvif\client.py", line 26, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: sqlite3 module is required for the SqliteCache

Process finished with exit code 1

This appears to be caused by the zeep package requiring sqlite3 but not including it in their list of dependencies in setup.py or in a requirements.txt file. From what I can tell they've implemented somewhat of a workaround for this, i.e. you can use a Transport object with no cache, and using this approach will get you past the above error (include transport=Transport(cache=None) in the arguments for the ONVIFCamera instance creation). The root cause is that the zeep code attempts to import sqlite3 and if it's missing then it later croaks if no transport has been specified, since that will trigger an attempt to create an SqliteCache, which is what requires the sqlite3 package.

Assuming the above is correct then the above error is caused by either 1) sqlite3 is not in the environment already, or 2) a cacheless Transport is not specified as the transport argument when instantiating an ONVIFCamera object. I'm not convinced that this is an error per se with either zeep or this package.

Maybe this is best remedied by simply adding a note in the documentation regarding the use of an sqlite database for zeep's caching, or defaulting to using a cacheless Transport when creating an ONVIFCamera object?

If there are other ideas as to the best way forward then please comment (@mvantellingen may advise?) as I may be able to help with a bit of guidance, although I'm completely new to all of this and the above issue report may be all I'm good for here. In any event big thanks for providing this package, as it looks to be very promising for some upcoming work that I'll be doing with ONVIF-compliant devices.

andrepesi commented 1 year ago

did you find the solution? I have the same problem