I am a bit confused for my implementation. I have a Python script to be embedded into C++.
import urllib.request
import ssl
import suds.transport.http
from suds.client import Client
class UnverifiedHttpsTransport(suds.transport.http.HttpTransport):
def __init__(self, *args, **kwargs):
super(UnverifiedHttpsTransport, self).__init__(*args, **kwargs)
def u2handlers(self):
handlers = super(UnverifiedHttpsTransport, self).u2handlers()
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
handlers.append(urllib.request.HTTPSHandler(context=context))
return handlers
url="https://xxxxxest.com/datamanagement.asmx?WSDL"
client = Client(url, transport=UnverifiedHttpsTransport())
def ReadDataTest():
result = client.service.ReadTestData()
return result
def ReadGridData():
result = client.service.ReadGridData()
return result
def main():
result=ReadGridData()
print(result)
if __name__ == "__main__":
main()
Then sample_main.cpp
has plugin lib
sample_plugin.cpp.
sample_plugin.cpp has python embedded code as follows.
Py_Initialize();
pName = PyUnicode_DecodeFSDefault("web_interface");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule != NULL) {
pFunc_readtest = PyObject_GetAttrString(pModule, "ReadDataTest");
if (pFunc_readtest && PyCallable_Check(pFunc_readtest)) {
pValue = PyObject_CallObject(pFunc_readtest, NULL);
if(pValue != NULL) {
printf("Result of call: %s\n", pValue);
Py_DECREF(pValue);
}
}
Py_XDECREF(pFunc_readtest);
Py_DECREF(pModule);
}else{
PyErr_Print();
printf("Can't call python \n");
}
Py_FinalizeEx();
When I run sample_main.exe, I have errors as
Traceback (most recent call last):
File "/opt/nvidia/deepstream/deepstream-5.0/sources/apps/sample_apps/deepstream-test3/web_interface.py", line 2, in <module>
import ssl
File "/usr/lib/python3.6/ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: /usr/lib/python3.6/lib-dynload/_ssl.cpython-36m-aarch64-linux-gnu.so: undefined symbol: PyExc_OSError
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ImportError: /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-aarch64-linux-gnu.so: undefined symbol: PyExc_ValueError
Original exception was:
Traceback (most recent call last):
File "/opt/nvidia/deepstream/deepstream-5.0/sources/apps/sample_apps/deepstream-test3/web_interface.py", line 2, in <module>
import ssl
File "/usr/lib/python3.6/ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: /usr/lib/python3.6/lib-dynload/_ssl.cpython-36m-aarch64-linux-gnu.so: undefined symbol: PyExc_OSError
The error is removed when I include Py_Initialize(); inside sample_main.cpp
.
Why is it necessary to include Py_Initialize(); inside sample_main.cpp
?
Is that the right way to do that? What are the things I need to care inside
sample_main.cpp
for memory leak or anything other issues?