I have a python script called web_interface.py
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://xxxxxx.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():
ReadGridData()
if __name__ == "__main__":
main()
Trying to call this script from c++ program as
Py_Initialize();
pName = PyUnicode_DecodeFSDefault("web_interface");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, "ReadDataTest");
if (pFunc && PyCallable_Check(pFunc)) {
pString=PyObject_CallObject(pFunc, NULL);
if(pString != NULL) {
printf("Result of call: %s\n", pString);
Py_DECREF(pString);
}
}
Py_XDECREF(pFunc);
Py_DECREF(pModule);
}else{
printf("Can't call python \n");
}
Py_FinalizeEx();
Always have "Can't call python \n"
What could be wrong?
EDIT: The place called the python script is inside a timer callback function. When export $PYTHONPATH to the folder where python script is located, the error is
Can't call python
Exception ignored in: <module 'threading' from '/usr/lib/python3.6/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 1289, in _shutdown
assert tlock.locked()
SystemError: <built-in method locked of _thread.lock object at 0x7f77a1b580> returned a result with an error set