err=23 when updating textboxes - python-3.x

I'm getting the following error when updating text boxes:
load glyph failed err=23 face=0x0, glyph=19
All of the lines responsible for updating the text boxes look like this the par:
self.lnePer1_temp.setText(str(values_s[0]))# + " °C")
The method which aggregates these methods is called like this:
def timer_handler(self):
self.pressedSearchDevices()
if self.grbKeys1.isEnabled():
self.pressedKey1_bat()
if self.grbKeys2.isEnabled():
self.pressedKey2_bat()
if self.grbPer1.isEnabled():
self.pressedPer1_read_all()
if self.grbPer2.isEnabled():
self.pressedPer2_read_all()
threading.Timer(60, lambda: self.timer_handler()).start()
Basically it checks periodically whether some devices are available and updates the textboxes accordingly. When commented out - everything works fine. The full method responsible for updating the textboxes is:
def pressedPer2_read_all(self):
call('./reset_ble.sh', shell=True)
cmd = "sudo node Per_read_all.js " + Per_2.lower()
output = 'None'
with Popen(cmd, shell=True, stdout=PIPE, preexec_fn=os.setsid) as process:
try:
output = process.communicate(timeout=5)[0]
except TimeoutExpired:
os.killpg(process.pid, signal.SIGINT) # send signal to the process group
output = process.communicate()[0]
print(output)
output_s = output.decode("utf-8")
values_s = output_s.split('\n')
for s in values_s: print(s + " °C")
if len(values_s) == 7:
self.lnePer2_temp.setText(str(values_s[0]))# + " °C")
self.lnePer2_dig.setText(str(values_s[1]))
self.lnePer2_light.setText(str(values_s[2]))# + " %")
self.lnePer2_hum.setText(str(values_s[3]))# + " %")
self.lnePer2_alert.setText(str(values_s[4]))
self.lnePer2_but.setText(str(values_s[5]))
else:
self.lnePer2_temp.setText(" °C")
self.lnePer2_dig.setText(" ")
self.lnePer2_light.setText(" %")
self.lnePer2_hum.setText(" %")
self.lnePer2_alert.setText(" ")
self.lnePer2_but.setText(" ")
When replacing the if-else statement with only the else statement - everything works fine, so I'm assuming that the error lies in the change of values or something like that. Similar error messages link to Qt, so I'm also assuming that the fault lies somewhere there.
The script is running on a Raspberry Pi Zero, the Python Version used is Python 3.4.2, the PyQt5 version is 5.3.2.

Related

Telnet.read_very_eager in FOR loop and the first often returns b' ' while the rest works fine

I'm using Telnetlib to control a VIAVI 5800.Here is my code.
And I log results of telnet.read_very_eager. Sometimes the first read returns b'', maybe say it occurs a lot. I really don't understand why only the first read has this problem while the others just work fine. I also tried adding more time after I finishing changing the time slot, this still happens.
import telnetlib
import time
from robot.libraries.BuiltIn import BuiltIn
for vc4 in range(vc4, vc4_end):
for tug3 in range(stm_start, tug3_end):
for tug2 in range(1, 8):
for tu12 in range(1, 4):
tu12_com = ":SENSE:SDH:DS1:E1:LP:C12:CHANNEL" + " " + str(tu12) + "\n"
tug2_com = ":SENSE:SDH:DS1:E1:LP:C2:CHANNEL" + " " + str(tug2) + "\n"
tug3_com = ":SENSE:SDH:DS1:E1:LP:C3:CHANNEL" + " " + str(tug3) + "\n"
vc4_com = ":SENSE:SDH:CHANNEL:STMN" + " " + str(vc4)
tn.write(tu12_com.encode('ascii')) # change tu12
time.sleep(0.1)
tn.write(tug2_com.encode('ascii')) # change tug2
time.sleep(0.1)
tn.write(tug3_com.encode('ascii')) # change tug3
time.sleep(0.1)
tn.write(vc4_com.encode('ascii')) # change vc4
time.sleep(1.5)
tn.write(b":ABOR\n")
time.sleep(1)
tn.write(b":INIT\n")
time.sleep(5)
tn.write(b":SENSE:DATA? TEST:SUMMARY\n")
time.sleep(2)
result = tn.read_very_eager()
result_num = str(vc4) + "-" + str(tug3) + "-" + str(tug2) + "-" + str(tu12)
BuiltIn().log_to_console(result_num)
BuiltIn().log_to_console(result)
The results are like under:
results saved in excel workbook
results in RF Ride console
I'm so confused and wondering can anyone explain this. Thanks a lot.
BTW, my python version is:
C:\Users\Quinn>python -V
Python 3.7.9

Is it possible to interact with the subprocess 3 standards streams on windows?

I have a script that opens a subprocess, this process awaits multiple inputs.
I tried with subprocess.Popen() but when combining the 3 standards streams it gets stuck in deadlocks...
So I tired to use wexpect (Apparently Windows version of pexecpt) it also didn't worked.
Now I'm using Sarge and my code right now looks like this:
import os
import subprocess
import sarge
import sys
def get_env():
env = os.environ.copy()
return env
def interactive(list_command: list, instruction_dict: dict):
env = get_env()
std_out = ""
for a_number in instruction_dict:
capture_stdout = sarge.Capture(buffer_size=-1)
capture_stderr = sarge.Capture(buffer_size=-1)
child_proc = sarge.Command(list_command, stdout=capture_stdout, stderr=capture_stderr,
shell=True, env=env)
child_proc.run(input=subprocess.PIPE,
async_=True)
print(capture_stdout.readlines(timeout=1.0), capture_stderr.readlines(timeout=1.0))
if instruction_dict[a_number][0] is not None:
#if capture_stdout.expect(instruction_dict[a_number][0]) is not None or capture_stderr.expect(instruction_dict[a_number][0]) is not None:
# self.test_manager.log_event(msg="found line : " + instruction_dict[a_number][0] + "in PIPE", current_event_type=LogLevel.DEBUG, screen_only=False)
print("in exec line : ", child_proc.stdout.readline(timeout=1.0), child_proc.stderr.readlines(timeout=1.0))
else:
print("in exec line : ", child_proc.stdout.readlines(timeout=1.0), child_proc.stderr.readlines(timeout=1.0))
if instruction_dict[a_number][1] is not None:
print(f"sending \"{instruction_dict[a_number][1]}\" to process in interactive")
temp_bytes = str.encode((instruction_dict[a_number][1]+"\n"))
child_proc.stdin.write(temp_bytes)
try:
child_proc.stdin.flush() # blind flush
except:
pass
print("Last line : ", child_proc.stdout.readlines(timeout=1.0), child_proc.stderr.readlines(timeout=1.0))
child_proc.wait()
std_out += child_proc.stdout.read().decode('utf-8')
child_proc.kill() # kill the subprocess
print("output: ", std_out)
interactive(list_command=["process.exe", "-delete_datamodel", "MODELNAME"],instruction_dict={1 : (None, "y")})
Output looks like this:
[] []
in exec line : [] []
send "y" to process in interactive
Last line : [] [b'User root connected to DB MODELNAME\r\n']
output: Are you sure to delete DB MODELNAME? (y/n)\n\nDelete Data Model Ok\n
In console it looks like this:
C:\>process.exe -delete_data_model -db_name MODELNAME
Are you sure to delete DB MODELNAME ? (y/n)
y
User root connected to DB MODELNAME
Delete Data Model Ok
There are multiple problems:
I can't catch the first stdout "Are you sure to delete DB MODELNAME ? (y/n)" during the loop I only get [].
capture_stdout.expect crash but in fact it might be the same problem as the first one, if it can't read the first stdout.
lines are going in stderr instead of stdout (it might be because of the process, I don't know how to test this)
for another command I ll need to answer more than one interactive by looking of the question before answering them that way my instruction_dict will look like this
instruction_dict = {1 : ("Are you sure to recover the DB", "y"),
2 : ("Do you want to stop the service", "y"),
3 : ("Do you want to stop the DB", "y"),
4 : ("Do you want to drop and create the DB", "y")}
Is this even possible? I have search for a working exemple and didn't found one, I know I might be bad at searching but...
Sorry for the terrible syntax(and bad english), I want to know if there is a pure python solution (I have one solution working in tcl but I'm trying to get rid of it/ I didn't wrote the tcl code).

I want to exception of linux command

I want to control on python
try catch wifi list and connect to catching wife name and password
but I use linux command so I can't care linux error window
I want to check password in python
when i set wrong password, open Network manager.
What should i do?
import commands
def space_filter(x):
if x == ' ':
pass
else:
return x
#fail, output = commands.getstatusoutput("nmcli dev wifi list")
test= commands.getoutput("nmcli dev wifi list")
test1=test.split(' ')
print test
print test1
test2 = []
test1 = list(filter(space_filter, test1))
#print test1
for x in range(len(test1)):
if test1[x] == '\n*' or test1[x] =='\n':
test2.append(test1[x+1])
#print test2
try:
result = commands.getoutput("nmcli d wifi connect " + test2[0] + " password 1234")
print result
except:
print "password is wrong"[enter image description here][1]
Exceptions are a language specific construct to catch abnormal/error situations. The correct way to check error conditions in shell commands is the return value.
Use the getstatusoutput function in commands module to catch the return value along with the output. In your case, you would need to parse the output along with the return code to get the reason for failure since nmcli only distinguishes between certain kinds of failure. - https://developer.gnome.org/NetworkManager/stable/nmcli.html
(status, output) = commands. getstatusoutput("nmcli d wifi connect " + test2[0] + " password 1234")
if not status:
print "error"

How to make Discord bot send image with the name of number chosen by user? (Python 3.5.x)

I'm still learning python and programming and i've got myself into a problem that i can't solve. I want to make a command that would make a bot send an image that its name corresponds to number what user wrote (e.g. user wrote "!image_nr 22" and bot sends 22.jpg). I've only made code that sends random image from folder but I cant get into chosen. Here's my latest code for this problem:
elif message.content.startswith("!obrazeknr"): #missing an argument or something, idk what to make here
obrazDirectoryChc = "C:/Users/Lewando54/Downloads/Localisation/English/" + liczba + ".jpg"
await client.send_file(message.channel, obrazDirectoryChc, content=obrazName[1])
You could try inside this elif statement:
msg = message.content[12:] #skips the command word and the '!' and the " "
msg = msg.split() #split the message into an array at the spaces.
#msg = ["!image_nr","22"]
if msg[0] == "!image_nr" and msg[1].isnumeric():
obrazDirectoryChc = "C:/Users/Lewando54/Downloads/Localisation/English/" +
liczba + ".jpg"
await client.send_file(message.channel, obrazDirectoryChc,
content=obrazName[int(msg[1]])
now it should send the user requested photo.
e.g. !obrazeknr image_nr 22
Hope this helps. Sorry for the long wait; I just saw this today.
Might be a better idea, for next time, posting on https://programming.stackoverflow.com could give you more help.
It works. I've slightly modified it and it works. Thx for idea :D
elif message.content.startswith('!obrazeknr'):
msg1 = message.content #skips the command word and the '!' and the " "
msg1 = msg1.split() #split the message into an array at the spaces.
#msg = ["!obrazeknr","22"]
if msg1[0] == "!obrazeknr" and msg1[1].isnumeric() == True:
await client.send_file(message.channel, "C:/Users/Lewando54/Downloads/Localisation/English/" + str(int(msg1[1])) + ".jpg")

gmail notifier code python

I have just started with Python a few days earlier, and now I am trying to make a Gmail notifier for Arduino using Python. I am getting the following error. I have entered my username and ID properly, I have even tried putting application specified code given by Google, but I'm still getting this error.
import serial, sys, feedparser,time
#Settings - Change these to match your account details
USERNAME="XXXX"
PASSWORD="XXXXXXX"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom/important"
try:
ser = serial.Serial("COM3", 9600)
except serial.SerialException:
print ("no device connected exiting")
sys.exit()
newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "#" + SERVER + PATH)["feed"]["fullcount"])
# Output data to serial port
if newmails > 0:
ser.write("m")
print("some mail")
else:
ser.write("n")
print("no mail")
#print data to terminal
# Close serial port
ser.close()
ERROR IS FOLLOWING :- C:\Python33>python mailarduino.py Traceback
(most recent call last): File "mailarduino.py", line 13, in
newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD +
"#" + SE RVER + PATH)["feed"]["fullcount"]) File
"C:\Python33\lib\site-packages\feedparser-5.1-py3.3.egg\feedparser.py",
l ine 346, in getitem return dict.getitem(self, key) KeyError:
'fullcount'
C:\Python33>
The tutorial you are copying is 5 years old. API's, which are the functions you can call and what they return, can change over time. I suggest printing out:
feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "#" + SERVER + PATH)
and see what that produces. Once you see what you have, then you can work out how to extract the info you want.

Resources