Importing the python script to uipath/ Error loading Script

anyone knows how to solve this error?

import speech_recognition as sr
import webbrowser as wb

chrome_path = ‘C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s’

r = sr.Recognizer()

with sr.Microphone() as source:
print (‘Say something’)
audio = r.listen(source)
print (‘Done’)

try:
text = r.recognize_google(audio)
print(‘Google thinks you said:\n’ + text)
wb.get(chrome_path).open(text)

except Exception :
print

Hello,

Did you tried this script outside UiPath? Could you show you Invok Python Script activity?

Working with python in UiPath is really a PITA as it is now:

  • Encoding errors
    You can’t work with non-ASCII without adpating your python

  • PYTHONPATH
    Well, if you work with packages, importing other modules is quite a sport.

  • Traceback
    Don’t ask for it :slight_smile: You’d better have solid logs. To begin with,

# Your script with formatting
import speech_recognition as sr
import webbrowser as wb

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

r = sr.Recognizer()

with sr.Microphone() as source:
	print ('Say something')
	audio = r.listen(source)
	print (‘Done’)

try:
	text = r.recognize_google(audio)
	print('Google thinks you said:\n' + text)
	wb.get(chrome_path).open(text)
except Exception:
	print

sorry, I don’t unds… please explain. thanks!

Could you please make a screenshot of your Load Python Script? Did you try to run your script from the command line before integrating it to UiPath?

Yes it works fine before integrating it to uipath.

Nice.

Could you make a screenshot of your Load Python Script activity in UiPath, please?

this is the error when I run…

Thanks

If the following doesn’t fix your problem, could you please click on “Details” in the error and copy/paste the content?

Just thought about it: I’m not sure what is the standard output for your prints when launched from UiPath. In this context, I would let UiPath print the instructions. The script should return the string to print as a result and you’ll manage the resulting print from UiPath

the content is this "RemoteException wrapping System.InvalidOperationException: Error loading Python script —> RemoteException wrapping System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: ModuleNotFoundError : No module named ‘speech_recognition’

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.LoadScript(String code)
at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass11_0.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.LoadScript.d__12.MoveNext()
— End of inner exception stack trace —
at UiPath.Python.Activities.LoadScript.d__12.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)"

the output is supposed to be like eg. when i say "open youtube.com " then it would open

Erf…I can’t make sense of that, sorry…

Could you comment the prints in your script and run UiPath? Just to put my theory in trial.

could you show me how to do it? as I’m not sure how.

(https://www.youtube.com/watch?v=fvs29wjFKy8)

£I would like the result to be similar to the video.

thanks.

I understand, we’ll come to the result later. (I’ll watch your link in about 2-3 hours.

# Your script with formatting
import speech_recognition as sr
import webbrowser as wb

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

r = sr.Recognizer()

with sr.Microphone() as source:
	# print ('Say something')
	audio = r.listen(source)
	# print (‘Done’)

try:
	text = r.recognize_google(audio)
	# print('Google thinks you said:\n' + text)
	wb.get(chrome_path).open(text)
except Exception:
	pass

EDIT: I saw the video :wink: Once you’ll check that getting rid of the prints fix the problem, you might want to choose between:

  • Write to a file (you can use Notepad++ to monitor file as soon as it change, see screenshot below)
  • Change the standard outpout
  • Return the results and handle back and forth communication between UiPath and Python.

image

sorry I still dont get it…

Could you please use my edited version of your python script and see if chrome open?

very impressive

I still don’t understand, the code is shown when i run in chrome. can you show me how?

thanks.

When you use the code I edited and launch your UiPath Script, what happen?

the same error will appear. please show me how. thanks.

can you please help me?:slight_smile: