# Error invoking Python method

**URL:** <https://forum.uipath.com/t/error-invoking-python-method/123258>\
**Category:** Help\
**Tags:** studio, python, activities\
**Created:** [June 7, 2019, 6:17am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258 "2019-06-07T06:17:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nalini](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nalini/32/176864_2.png) [@Nalini](https://forum.uipath.com/u/Nalini)\
**Post date:** [June 7, 2019, 6:17am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/1 "2019-06-07T06:17:10Z")

</div>

Error invoking Python method

we had written the code for text to speech in jupyter notebook then it is giving perfect output, but when we try to run this code in UiPath using python activity we are getting error i.e., Error invoking Python method

18.3.3+Branch.master.Sha.dad278851683d948236b522f6a0c8dd584803e65

Source: Invoke Python Method

Message: Error invoking Python method

Exception Type: System.InvalidOperationException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:  
System.InvalidOperationException: Error invoking Python method ----\> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: PlaysoundException :  
Error 266 for command:  
open “C:\Users\Nalini\Documents\UiPath\Python\9603974randomtext.mp3” alias playsound\_0.8404515335860276  
Unknown problem while loading the specified device driver.

Server stack trace:  
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)  
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)  
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout)  
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)  
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:  
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)  
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)  
at UiPath.Python.Service.IPythonService.InvokeMethod(Guid instance, String method, IEnumerable`1 args) at UiPath.Python.Impl.OutOfProcessEngine.<>c __DisplayClass12_0.<InvokeMethod>b__ 0() at System.Threading.Tasks.Task`1.InnerInvoke()  
at System.Threading.Tasks.Task.Execute()  
— End of stack trace from previous location where exception was thrown —  
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)  
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
at UiPath.Python.Activities.InvokeMethod.d\_\_16.MoveNext()  
— End of inner ExceptionDetail stack trace —  
at UiPath.Python.Activities.InvokeMethod.d\_\_16.MoveNext()  
— End of stack trace from previous location where exception was thrown —  
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)  
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)  
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

---

<div class="post-metadata">

**Author:** ![lakshman](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshman/32/523490_2.png) [@lakshman](https://forum.uipath.com/u/lakshman)\
**Post date:** [June 7, 2019, 6:23am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/2 "2019-06-07T06:23:33Z")

</div>

@Nalini

Welcome to the UIPath Community.

Please check below thread and follow steps.

> **[Python Scope](https://docs.uipath.com/activities/docs/python-scope)**
>
> UiPath.Python.Activities.PythonScope A container which provides a scope for Python activities and initializes the specified Python environment. When the Python Scope activity ends, all Python objects loaded up to that point are deleted. Properties...

---

<div class="post-metadata">

**Author:** ![Nalini](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nalini/32/176864_2.png) [@Nalini](https://forum.uipath.com/u/Nalini)\
**Post date:** [June 7, 2019, 6:27am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/3 "2019-06-07T06:27:49Z")

</div>

we have already tried one small example of python code in uipath ,it is working.But when we tried to run the code for text to speech through uipath we are getting this invoke method error

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [June 7, 2019, 6:29am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/4 "2019-06-07T06:29:50Z")

</div>

> [@Nalini](#):
>
> Error 266 for command:  
> open “C:\Users\Nalini\Documents\UiPath\Python\9603974randomtext.mp3” alias playsound\_0.8404515335860276  
> Unknown problem while loading the specified device driver.

Hi  
The error occurred here while invoking the code  
kindly check whether the voice driver or the above specified driver is installed or enabled properly in your system  
Cheers @Nalini

---

<div class="post-metadata">

**Author:** ![HareeshMR](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/hareeshmr/32/181825_2.png) [@HareeshMR](https://forum.uipath.com/u/HareeshMR)\
**Post date:** [June 7, 2019, 6:32am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/5 "2019-06-07T06:32:29Z")

</div>

> [@Nalini](#):
>
> Error 266 for command:  
> open “C:\Users\Nalini\Documents\UiPath\Python\9603974randomtext.mp3” alias playsound\_0.8404515335860276  
> Unknown problem while loading the specified device driver.

Hi @Nalini ,

It’s showing some error with the device loading… Don’t know what exactly it is.

Previously, when i tried to use tessaract OCR in my code, It asked me to involve the application exe file. May be you need to include the driver you want to use in the code itself.

Here is my code which I’m using (Just for your reference) 🙂

try:  
from PIL import Image  
except ImportError:  
import Image  
import pytesseract

pytesseract.pytesseract.tesseract\_cmd = r"C:\Users\hamadasi\AppData\Local\Tesseract-OCR\tesseract.exe"

#filename = ‘D:\Python screenshot\Deepfieldglass.png’

def ocr\_core(filename = None):  
if filename is None:  
#filename = ‘D:\Python screenshot\Deepfieldglass.png’  
return “file name is null”  
text = pytesseract.image\_to\_string(Image.open(filename)) # We’ll use Pillow’s Image class to open the image and pytesseract to detect the string in the image  
textfile = open(r"D:\UiPath files\Time sheets\Attachments\Deepfieldglass.txt",“w+”)  
textfile.write(text)  
#return text.encode(“utf-8”)  
return “Successful”

#print(ocr\_core(filename))

---

<div class="post-metadata">

**Author:** ![Nalini](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nalini/32/176864_2.png) [@Nalini](https://forum.uipath.com/u/Nalini)\
**Post date:** [June 7, 2019, 6:42am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/6 "2019-06-07T06:42:23Z")

</div>

hi @HareeshMR ,  
we installed play sound to get the audio in jupyter notebook . To run the same code in uipath do we need to install any other drivers  
Regards,  
Nalini.

---

<div class="post-metadata">

**Author:** ![Nalini](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nalini/32/176864_2.png) [@Nalini](https://forum.uipath.com/u/Nalini)\
**Post date:** [June 7, 2019, 6:50am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/7 "2019-06-07T06:50:24Z")

</div>

hi @Palaniyappan ,

how to check whether the driver is installed.actually we already installed playsound in python

Thanks&Regards,  
Nalini.

---

<div class="post-metadata">

**Author:** ![HareeshMR](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/hareeshmr/32/181825_2.png) [@HareeshMR](https://forum.uipath.com/u/HareeshMR)\
**Post date:** [June 7, 2019, 6:54am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/8 "2019-06-07T06:54:49Z")

</div>

> [@HareeshMR](#):
>
> pytesseract.pytesseract.tesseract\_cmd = r"C:\Users\hamadasi\AppData\Local\Tesseract-OCR\tesseract.exe"

You need to include the driver application within the code as per my understanding. Try this including the exe file as above. @Nalini

---

<div class="post-metadata">

**Author:** ![Nalini](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nalini/32/176864_2.png) [@Nalini](https://forum.uipath.com/u/Nalini)\
**Post date:** [June 7, 2019, 7:54am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/9 "2019-06-07T07:54:22Z")

</div>

hi @HareeshMR,  
Now we got a result,but it is a audio file.The result is stored in an object.Will you please help us how to play that audio in uipath

Regards,  
Nalini.

---

<div class="post-metadata">

**Author:** ![HareeshMR](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/hareeshmr/32/181825_2.png) [@HareeshMR](https://forum.uipath.com/u/HareeshMR)\
**Post date:** [June 7, 2019, 8:50am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/10 "2019-06-07T08:50:31Z")

</div>

Hi @Nalini,

Can you try saving that to a file with an extention .mp3 or .mp4 … as per your requirement?

Then try to open the file using Process.Open as in the screenshot… It will open with the default media player in your machine…

![image](https://global.discourse-cdn.com/uipath/original/3X/1/6/1654d55dd30ae684cb2631347954a41816dd7a3f.png)

I have given the windows media player exe there… but you need to give the path of the audio file you just saved.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [June 10, 2019, 8:50am UTC](https://forum.uipath.com/t/error-invoking-python-method/123258/11 "2019-06-10T08:50:36Z")

</div>

Closed on June 10, 2019, 8:50am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
