How to fix 'IndexError: index out of range' - python

I have built a simple app with Blynk. Unfortunately, I regularly get the error:
Traceback (most recent call last):
File "/home/pi/Desktop/Blynk/blynktest2.py", line 12, in <module>
blynk.run()
File "/home/pi/.local/lib/python3.7/site-packages/BlynkLib.py", line 252, in run
self.process(data)
File "/home/pi/.local/lib/python3.7/site-packages/BlynkLib.py", line 213, in process
self.emit("int_"+args[1], args[2:])
IndexError: list index out of range
Even if I take out all code on my hardware and end up with the following code, the error comes up:
import BlynkLib
BLYNK_AUTH = 'MY_AUTH_IS_NORMALLY_HERE'
# initialize blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
while True:
blynk.run()
I do not know exactly what causes the error, however, I noticed that the error occurs
when the Blynk app is moved to the background
when the screen of the mobile phone turns black
the eror does not occur when normal disconnecting in the Blynk app via the stop button in the top right, and also not if reconnecting then

This is one random issue which keeps happening. Try recreating the project by removing all the controllers or create a new project and update the authentication code in your code.

Related

issues running a face_recogition file using editors and cmd

When I run the code below in jupyter, it is excellent, I get the results I want.
real = fr.load_image_file("image.jpg")
unknown = fr.load_image_file("image2.jpg")
# encodings
real_encoding = fr.face_encodings(real)[0]
unk = fr.face_encodings(unknown)[0]
result = fr.compare_faces([real_encoding], unk)
print(result)
but when I copy and paste the same code to an editor(atom the one I am using), and then run it using command prompt, I get an error as shown below
Traceback (most recent call last):
File "face_recognizer.py", line 13, in <module>
real_encoding = fr.face_encodings(real)[0]
IndexError: list index out of range
I activated the environment in which I was running the cmd.
Can someone advise me where I maybe going wrong?
There was no face captured in the photo.
That is why it throws an exception.

viewer error when running the stokesCavity.py example

Running Manjaro stable with python-3.9 and python-fipy-3.4.2.1-1.
Just got started with FiPy, ultimately interested in writing single and two-phase flow code. Naturally I tried to run examples/flow/stokesCavity.py (stripped down from all rst text) with: python stokesCavity.py and it throws the following error:
Traceback (most recent call last):
File "/home/zbinkz/HGST/Projects/Python/fipy/examples/flow/stokesCavity.py", line 117, in <module>
viewer = Viewer(vars=(pressure, xVelocity, yVelocity, velocity),
File "/usr/lib/python3.9/site-packages/fipy/viewers/__init__.py", line 130, in Viewer
raise ImportError("Failed to import a viewer: %s" % str(errors))
ImportError: Failed to import a viewer: ["matplotlib: True is not a valid value for orientation; supported values are None, 'vertical', 'horizontal'", "mayavi: No module named 'enthought'"]
I tinkered with different values for FIPY_VIEWER in the viewer command at line 117 reported above but still get the same error. At this very early stage with FiPy I'm clueless, anybody know how to fix this?
Thanks :)
In this line, change
... viewer = Viewer(vars=(pressure, xVelocity, yVelocity, velocity),
... xmin=0., xmax=1., ymin=0., ymax=1., colorbar=True)
to
... viewer = Viewer(vars=(pressure, xVelocity, yVelocity, velocity),
... xmin=0., xmax=1., ymin=0., ymax=1., colorbar='vertical')
I've filed a ticket to correct this.

Instabot API for Python raises error after running code for the 2nd time

I am currently working with the Instabot API for python and I ran across the following issue:
I wrote a small program:
from instabot import Bot
bot = Bot()
bot.login(username = "[my username]", password = "[my passowrd]")
bot.follow("lego")
which worked fine after running it for the very first time. However, after running the program for a second time, this time following another account, it raised an error ("KeyError: ds_user").
This error can be fixed by deleting the config folder inside the project folder. Unfortunately, this isn't a very sustainable solution, as it makes working on the code really arduous. I therefore would like to know if there is any solution for getting the program to run multiple times without having to delete the config folder over and over again.
I am receiving the following traceback (code is running in an anaconda environment called "Instagram Automation"):
Traceback (most recent call last):
File "e:/Programme/OneDrive/Dokumente/Projekte/Instagram Automation/main.py", line 4, in <module>
bot.login(username = "[my username]", password = "[my password]")
File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\bot\bot.py", line 443, in login
if self.api.login(**args) is False:
File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\api\api.py", line 240, in login
self.load_uuid_and_cookie(load_cookie=use_cookie, load_uuid=use_uuid)
File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\api\api.py", line 199, in load_uuid_and_cookie
return load_uuid_and_cookie(self, load_uuid=load_uuid, load_cookie=load_cookie)
File "E:\Programme\Anaconda\envs\Instagram Automation\lib\site-packages\instabot\api\api_login.py", line 352, in load_uuid_and_cookie
cookie_username = self.cookie_dict["ds_user"]
KeyError: 'ds_user'
As far as I can see, the only way on your side to fight the symptoms is to always delete the JSON file in the config folder, e.g:
import os
if os.path.isfile("path/to/config/file.json"):
os.remove("path/to/config/file.json")
import instabot
# rest of your code goes here
The developers of instabot should fix the source of the problem, for example by using self.cookie_dict.get("ds_user", "some default value") instead of self.cookie_dict["ds_user"]

Where does this pywinauto exception get its list from?

If I run:
from pywinauto.findwindows import find_windows
find_windows(best_match="affafa")
I get an exception that returns
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\site-packages\pywinauto\findwindows.py", line 204, in find_windows
best_match, wrapped_wins)
File "c:\Python27\lib\site-packages\pywinauto\findbestmatch.py", line 497, in find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'affafa' in '[u'CabinetWClass', u'Inbox (1,455) - ******#gmail.com - Gmail - Google Chrome', u'Chrome_WidgetWin_1', '', u'*new 2 - Notepad++Notepad++', u'python - Where does this pywinauto exception get its list from? - Stack Overflow - Google ChromeChrome_WidgetWin_1', u'C:\\Windows\\system32\\cmd.exe - pythonConsoleWindowClass1', u'C:\\Windows\\system32\\cmd.exe - pythonConsoleWindowClass0', u'C:\\Windows\\system32\\cmd.exe - pythonConsoleWindowClass2']' # this list has been shortened for security reasons
What I want to do is,Find out where the giant list of processes is coming from and directly call that.
So far ive been messing around with
find_windows(visible_only = False)
# and some of the other options listed in findwindows.py
but all the find_windows options only return a list of numbers which from documentation, i think are process IDs...., which for some reason do NOT match up with what i have ( for example, i create a "Calculator" and its process ID is 6566, and then i run find_windows() and i cannot find the process ID in it. So that's another issue I'm having.... but i can solve this problem if i can get my giant list.
This is my first question asked on stack overflow. I hope I made you guys proud
If you want to get a list of the names for all windows, you should use the next construction.
handles = pywinauto.findwindows.find_windows()
for w_handle in handles:
wind = app.window_(handle=w_handle)
print wind.Texts()
You may filter/extend the list by the next arguments of find_windows function:
top_level_only Top level windows only (default=True)
visible_only Visible windows only (default=True)
enabled_only Enabled windows only (default=True)
active_only Active windows only (default=False)

How to interact with pynessus

I am using http://code.google.com/p/pynessus/ so that I can interact with nessus using python but I run into problems trying to connect to the server. I am not sure what I need to set pynessus too?
I try connecting to the server using the following syntax as directed by the documentation on the site but I receive the following error:
n = pynessus.NessusServer(localhost, 8834, root, password123)
Error:
root#bt:~/Desktop# ./nessus.py
Traceback (most recent call last):
File "./nessus.py", line 634, in
n = pynessus.NessusServer(localhost, 8834, root, password123)
NameError: name 'pynessus' is not defined
The problem is that you didn't import the pynessus module. To solve this problem, simply place the downloaded pynessus.py in the same folder as your Python script and add the line
import pynessus
at the top of that script. You can reference the pynessus library in your script only after that line.

Categories

Resources