Speech_Recognizer won't recognize - python

Robot:I'm Listening
Traceback (most recent call last):
File "C:\Users\HP\Documents\Code\nghe.py", line 8, in <module>
you = robot_ear.recognize_google(audio)
File "C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
I want to a robot hear me talk to him but can't

Related

controlling updown spinner elemnt using pywinauto

I am trying to control the value of a UpDown spinner element with pywinauto.
this is my element i want to control:
UpDown - 'Spinner' (L384, T624, R400, B642)
| | | | | ['Spinner', 'SpinnerUpDown', 'UpDown']
| | | | | child_window(title="Spinner", auto_id="68226", control_type="Spinner")
I am not sure how to get it's value and set it's value through pywinauto.
i have succeded doing it with button element, but the spinner element is not working while doing the examples and help i found on the internet.
my code goes like this:
from pywinauto.application import Application
app = Application(backend="uia").start('smcg2gui.exe')
# app.PololuSimpleMotorControlCenterG2.print_control_identifiers()
stop_motor = app.PololuSimpleMotorControlCenterG2.child_window(title="Stop motor", auto_id="stopMotorButton", control_type="Button")
speed_controller = app.PololuSimpleMotorControlCenterG2.child_window(title="Spinner", auto_id="7995854", control_type="Spinner")
speed_controller.get_value()
stop_motor.click()
print("done")
and i am getting this error:
Traceback (most recent call last):
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
ctrl = wait_until_passes(
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\owner\Desktop\try.py", line 12, in <module>
speed_controller.get_value()
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl
ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'Spinner', 'auto_id': '7995854', 'control_type': 'Spinner', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Pololu Simple Motor Control Center G2', WindowsForms10.Window.8.app.0.33c0d9d, 1835472>, 'backend': 'uia'}
so i tried doing it with wrapper_object:
from pywinauto.application import Application
app = Application(backend="uia").start('smcg2gui.exe')
# app.PololuSimpleMotorControlCenterG2.print_control_identifiers()
stop_motor = app.PololuSimpleMotorControlCenterG2.child_window(title="Stop motor", auto_id="stopMotorButton", control_type="Button")control_type="Button")
speed_controller = app.PololuSimpleMotorControlCenterG2.UpDown.wrapper_object()
print(speed_controller.iface_value.CurrentValue)
stop_motor.click()
print("done")
and got this:
Traceback (most recent call last):
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\uia_defines.py", line 234, in get_elem_interface
iface = cur_ptrn.QueryInterface(cls_name)
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\__init__.py", line 1197, in QueryInterface
self.__com_QueryInterface(byref(iid), byref(p))
ValueError: NULL COM pointer access
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\owner\Desktop\try.py", line 12, in <module>
print(speed_controller.iface_value.CurrentValue)
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
value = self.fget(obj)
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 252, in iface_value
return uia_defs.get_elem_interface(elem, "Value")
File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\uia_defines.py", line 236, in get_elem_interface
raise NoPatternInterfaceError()
pywinauto.uia_defines.NoPatternInterfaceError
i am a bit lost.
Thank you very much

configparser.NoSectionError: No section: 'creds' in Python

I'm getting configparser.NoSectionError: No section: 'creds
Config.cfg file
[creds]
token = telegram_bot_token
code.py file
class telegram_bot() :
def __init__(self,config):
self.token=self.read("config.cfg")
self.base="https://api.telegram.org/bot{}/".format(self.token)
def read(self,config):
self.parser=cfg.RawConfigParser()
self.parser.read(config)
return self.parser.get('creds','token')
Error
Traceback (most recent call last):
File "MAINSERVER.PY", line 5, in <module>
bots=telegram_bot("config.cfg")
File "G:\BOT\TBOT\bs4\qrcode\main.py", line 6, in __init__
self.token=self.read("config.cfg")
File "G:\BOT\TBOT\bs4\qrcode\main.py", line 24, in read
return self.parser.get('creds','token')
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\configparser.py", line 781, in get
d = self._unify_values(section, vars)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\configparser.py", line 1149, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'creds'
Anybody know what could be the issue ?

How of fix "'gbk' codec can't decode byte" error in python pdb tool?

There are some Chinese comments in my code. The pdb debugger will raise a UnicodeDecodeError only when some specific characters appear.
Here's the source file util.py:
"""代码清单 util.py"""
import json
def load_info(path):
"""读取json文件"""
with open(path) as f:
return json.load(f)
def print_info(info):
"""打印信息"""
for k, v in info.items():
print('{}: {}'.format(k, v))
def to_upper(info):
"""将键值中的字符串转为大写"""
for k, v in info.items():
if isinstance(v, str):
info[k] = v.upper()
return info
And here's the error message when I try to add a break point:
E:\10-写作\01-技术\01-Python\Python代码调试全面介绍\src
λ python -m pdb util.py
> e:\10-写作\01-技术\01-python\python代码调试全面介绍\src\util.py(1)<module>()
-> """代码清单 util.py"""
(Pdb) b print_info
Traceback (most recent call last):
File "D:\Python37\lib\pdb.py", line 648, in do_break
lineno = int(arg)
ValueError: invalid literal for int() with base 10: 'print_info'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python37\lib\pdb.py", line 659, in do_break
code = func.__code__
AttributeError: 'str' object has no attribute '__code__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python37\lib\pdb.py", line 1701, in main
pdb._runscript(mainpyfile)
File "D:\Python37\lib\pdb.py", line 1570, in _runscript
self.run(statement)
File "D:\Python37\lib\bdb.py", line 585, in run
exec(cmd, globals, locals)
File "<string>", line 1, in <module>
File "e:\10-写作\01-技术\01-python\python代码调试全面介绍\src\util.py", line 1, in <module>
"""代码清单 util.py"""
File "e:\10-写作\01-技术\01-python\python代码调试全面介绍\src\util.py", line 1, in <module>
"""代码清单 util.py"""
File "D:\Python37\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "D:\Python37\lib\bdb.py", line 112, in dispatch_line
self.user_line(frame)
File "D:\Python37\lib\pdb.py", line 261, in user_line
self.interaction(frame, None)
File "D:\Python37\lib\pdb.py", line 352, in interaction
self._cmdloop()
File "D:\Python37\lib\pdb.py", line 321, in _cmdloop
self.cmdloop()
File "D:\Python37\lib\cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "D:\Python37\lib\pdb.py", line 418, in onecmd
return cmd.Cmd.onecmd(self, line)
File "D:\Python37\lib\cmd.py", line 217, in onecmd
return func(arg)
File "D:\Python37\lib\pdb.py", line 667, in do_break
(ok, filename, ln) = self.lineinfo(arg)
File "D:\Python37\lib\pdb.py", line 740, in lineinfo
answer = find_function(item, fname)
File "D:\Python37\lib\pdb.py", line 100, in find_function
for lineno, line in enumerate(fp, start=1):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 329: illegal multibyte sequence
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> d:\python37\lib\pdb.py(100)find_function()
-> for lineno, line in enumerate(fp, start=1):
(Pdb)
But when after I remove some Chinese characters, there won't be any errors. I removed some comments for to_upper function:
def to_upper(info):
"""将键值中"""
for k, v in info.items():
if isinstance(v, str):
info[k] = v.upper()
return info
Then the error just is gone:
(Pdb) b print_info
Breakpoint 2 at e:\10-写作\01-技术\01-python\python代码调试全面介绍\src\util.py:11
The source file is encoded in UTF-8 format. I don't know what's going on here.

FramenetError: Unknown frame

I run:
from nltk.corpus import framenet as fn
fn.frames()
And get the following error:
Traceback (most recent call last):
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1308, in frame_by_name
elt = XMLCorpusView(locpath, 'frame')[0]
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/xmldocs.py", line 155, in __init__
encoding = self._detect_encoding(fileid)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/xmldocs.py", line 166, in _detect_encoding
with open(fileid, 'rb') as infile:
NotADirectoryError: [Errno 20] Not a directory: '/Users/me/nltk_data/corpora/framenet_v17.zip/framenet_v17/frame/Abandonment.xml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 876, in __repr__
for elt in self:
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/collections.py", line 406, in iterate_from
try: yield self._func(self._lists[0][index])
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1407, in frame
f = self.frame_by_id(fn_fid_or_fname, ignorekeys)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1268, in frame_by_id
return self.frame_by_name(name, ignorekeys, check_cache=False)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1310, in frame_by_name
raise FramenetError('Unknown frame: {0}'.format(fn_fname))
nltk.corpus.reader.framenet.FramenetError: Unknown frame: Abandonment
Both the Framenet 1.5 and 1.7 corpora are installed, according to nltk.download()

How to print the first line from a traceback stack

Suppose I am given the following traceback:
Traceback (most recent call last):
File "<wingdb_compile>", line 3, in <module>
File "C:\Python34\lib\ftplib.py", line 419, in login
resp = self.sendcmd('PASS ' + passwd)
File "C:\Python34\lib\ftplib.py", line 272, in sendcmd
return self.getresp()
File "C:\Python34\lib\ftplib.py", line 245, in getresp
raise error_perm(resp)
ftplib.error_perm: 530 Login incorrect.
I have managed to extract the Error details but what has stumped me is how would I extract the line:
File "<wingdb_compile>", line 3, in <module>
I was looking at methods in the trace back package but wondered if any one had experience with that here
The function traceback.format_exc is built primarily for this
This is like print_exc(limit) but returns a string instead of printing to a file.
>>> import traceback
>>> try:
... x = 2/0
... except:
... error = traceback.format_exc()
...
>>> error
'Traceback (most recent call last):\n File "<stdin>", line 2, in <module>\nZeroDivisionError: division by zero\n'
>>> linesoferror = error.split('\n')
>>> linesoferror
['Traceback (most recent call last):', ' File "<stdin>", line 2, in <module>', 'ZeroDivisionError: division by zero', '']
So now you wanted the first line then you can simply use
>>> linesoferror[1]
' File "<stdin>", line 2, in <module>'
Voila! You have what you want
ALERT - Valid for Python 2.4.1 and above

Categories

Resources