I am trying to make a program that translates whatever you say in Swedish and PyAutoGUI Typewrites it. But when I run the code, I just get the same error.
trans=Translator()
translating_text=input('Enter text to translate into S w e d i s h:')
t=trans.translate(translating_text,src='en',dest='sv')
time.sleep(5)
translated=t
pyautogui.typewrite(translated)
pyautogui.press('enter')
The error:
Traceback (most recent call last):
File "C:\Users\admin\Documents\Python Projects\CrendlePy.py", line 56, in <module>
ahm_swedish()
File "C:\Users\admin\Documents\Python Projects\CrendlePy.py", line 54, in ahm_swedish
pyautogui.typewrite(translated)
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-
packages\pyautogui\__init__.py", line 586, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-
packages\pyautogui\__init__.py", line 1665, in typewrite
for c in message:
TypeError: 'Translated' object is not iterable
Can someone pls help me with this?
Error speaks for its self, pyautogui.typewrite() is expecting iterable, for example, string, but you are passing Translated object.
You have to explore the way to get text out of your Translated object and only then pass it to pyautogui.
Related
Whenever I try to use this looping functionality, it gives me an error that has lines that are further than the end of my code. I am fairly new to python and coding in general, but I think this is part of a repository I downloaded. The error code looks like this
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 603, in run
self._do_run()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 590, in _do_run
data = self.source.read()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 543, in read
ret = self.original.read()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 228, in read
ret = self._stdout.read(OpusEncoder.FRAME_SIZE)
AttributeError: 'NoneType' object has no attribute 'read'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 616, in _call_after
self.after(error)
File "main.py", line 242, in play_next_song
raise VoiceError(str(error))
VoiceError: 'NoneType' object has no attribute 'read'
My Entire code block is here. I am trying to host this discord bot in repl.it, if that has anything to do with it.
Any help would be appreciated, Thanks!
The relevant part of the stacktrace is actually the last one:
File "main.py", line 242, in play_next_song
raise VoiceError(str(error))
VoiceError: 'NoneType' object has no attribute 'read'
You cannot use the same FFmpegPCMAudio object twice. You have the create a new one.
I have a Python script obtained from a project which I am trying to debug however I am unable to resolve one error. Per the author's description of the project, everything works fine.
The script takes a parameter called "ascii" which is of type str as shown below:
parser.add_argument('--ascii', type=str,
help='ASCII Data type: ASCII characters')
Per my understanding, in the following code, it processes the input string one character at a time and each character is sent to a function, iter_bin() which will take the ASCII value of the character and convert it to binary, appending the output to a list.
ASCIIDATA = args.ascii
dataArray = []
for line in ASCIIDATA:
for entry in line:
# Make sure everything is a number, convert if not
dataArray.append(''.join(s for s in iter_bin(entry)))
def iter_bin(s):
sb = s.encode('ascii')
return (format(b, '07b') for b in sb)
When I run this code, I get the following error:
Traceback (most recent call last):
File "check.py", line 107, in <module>
main()
File "check.py", line 70, in main
dataArray.append(''.join(s for s in iter_bin(entry)))
File "check.py", line 70, in <genexpr>
dataArray.append(''.join(s for s in iter_bin(entry)))
File "check.py", line 82, in <genexpr>
return (format(b, '07b') for b in sb)
ValueError: Unknown format code 'b' for object of type 'str'
How can I resolve this error?
Thanks.
I'm trying to automate tasks for teamcenter using pywinauto python module.But I was not able to work properly with TreeViews. When ever I'm trying to use GetItem(),SubElements(),Item() and many other function under _treeview_element giving error.Please look into below errors.
I'm using python 2.7 and i also have pywin32 module installed
for i in range(tr.ItemCount()):
print tr.GetItem(i)
Traceback (most recent call last):
File "<pyshell#61>", line 2, in <module>
print tr.GetItem(i) File "C:\Users\patibj\Desktop\pywinauto-
master\pywinauto\controls\common_controls.py", line 1010, in GetItem
if isinstance(path[0], int):
TypeError: 'int' object has no attribute '__getitem__'
This is when i'm trying to use GetChild()
a[0] is <pywinauto.controls.common_controls._treeview_element object at 0x02EC11B0> a[0].GetChild((1))
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
a[0].GetChild((1))
File "C:\Users\patibj\Desktop\pywinauto- master\pywinauto\controls\common_controls.py", line 840, in GetChild
return self.Children()[index]
File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 739, in Children
if self.Item().cChildren not in (0, 1):
File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 539, in Item
return self._readitem()[0]
File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 904, in _readitem
raise ctypes.WinError() WindowsError: [Error 0] The operation completed successfully.
Please help me out .Thanks in advance.
TreeViewWrapper.GetItem() method gets path argument which should be the string starting with back-slash \\ symbol. Example:
app.Dialog.TreeView.GetItem('\\1st_level_item_name\\2ndlevelitem').Click()
For access by index use a list of integers:
app.Dialog.TreeView.GetItem([1, 0])
GetChild() works with explorer.exe TreeView:
>>> tree.GetItem([1]).GetChild(2).Text()
u'Computer'
I am unable to use a example from there
I am testing out the sample here
http://cloud.verizon.com/documentation/AuthenticationRESTCallExample.htm
I am calling them by using (This is for sample)
secretKey="xxxxxxxxx"
accessKey="Xxxxxxxxx"
restVerb="GET"
apiResource="'https://api.cloud.verizon.com/api/cloud/vdisk-template/"
VzREST(secretKey,accessKey).request(restVerb,apiResource)
But I am getting a error like
Traceback (most recent call last):
File "C:\Python34\admins\a1.py", line 176, in <module>
VzREST(secretKey,accessKey).request(restVerb,apiResource)
File "C:\Python34\admins\a1.py", line 171, in request
restVerb,apiResource=apiResource),data=data)
File "C:\Python34\admins\a1.py", line 103, in _reqREST
apiResource = self._stripAndEncodeApiResource(apiResource)
File "C:\Python34\admins\a1.py", line 45, in _stripAndEncodeApiResource
return re.sub(self._url, '', apiResource.encode('ascii', 'ignore'))
File "C:\Python34\lib\re.py", line 175, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: can't use a string pattern on a bytes-like object
What's the error I am making here? Whether I am calling it wrongly (I am not so good in Python)
I have a function that decodes an exception and pushes the info to a file. Following is what I do basically:
exc_info = sys.exc_info
txt = cgitb.text(exc_info)
Using this, I got the following exception trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\job_queue\utils\start_workers.py", line 40, in start_worker
worker_loop(r_jq, worktype, worker_id)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 55, in worker_loop
_job_machine(*job)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 34, in _job_machine
do_verbose_exception()
File "C:\Python27\lib\site-packages\job_queue\server\errors.py", line 23, in do_verbose_exception
txt = cgitb.text(exc_info)
File "C:\Python27\lib\cgitb.py", line 214, in text
formatvalue=lambda value: '=' + pydoc.text.repr(value))
File "C:\Python27\lib\inspect.py", line 885, in formatargvalues
specs.append(strseq(args[i], convert, join))
File "C:\Python27\lib\inspect.py", line 840, in strseq
return convert(object)
File "C:\Python27\lib\inspect.py", line 882, in convert
return formatarg(name) + formatvalue(locals[name])
KeyError: 'connection'
I ran the code multiple times after this exception, but couldn't reproduce it. However, I didn't find any reference in files cgitb.py or inspect.py to a dict with 'connection' key either.
Will anybody know if this is an issue with python's cgitb or inspect files? Any helpful inputs?
You passed a wrong type to text function
below is the correct way.
cgitb.text((sys.last_type, sys.last_value, sys.last_traceback))
Im not sure specifically why this exception is happening, but have you read the docs for cgitb module? It seems that since python 2.2 it has supported writing exceptions to a file:
http://docs.python.org/library/cgitb.html
Probably something like:
cgitb.enable(0, "/my/log/directory") # or 1 if you want to see it in browser
As far as your actual traceback, are you sure 'connection' isnt a name you are using in your own code? 'inspect' module is most likely trying to examine your own code to build the cgi traceback info and getting a bad key somewhere?