在 pysimplegui 循环中第一次发送后,socket.send 停止工作
我正在尝试构建一个简单的 GUI,包括一个二维码读取器,以便使用 Ubuntu 上的 Python 将数据发送到远程服务器,用于学校项目。我已经设置了一个简单的服务器来接收来自 sca 的消息...
我正在尝试构建一个简单的 GUI,包括一个二维码读取器,以便使用 Ubuntu 上的 Python 将数据发送到远程服务器,用于学校项目。我已经设置了一个简单的服务器,通过 tcp/ip 接收来自扫描仪的消息:
import socket
from Crypto.Cipher import AES
def main():
# Server mit gegebener Adresse starten
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("192.168.1.40", 9999))
server.listen()
while True:
client, address = server.accept()
msg = client.recv(1024).decode('ASCII')
print(msg)
if __name__ == '__main__':
main()
如果我运行一个简单的测试客户端,所有消息都会被收到:
import socket
client = socket.socket()
try:
client.connect(("192.168.1.40",9999))
for i in range(1,10):
client.send("\nHallo Server, ich bin dein Client und will was\n".encode('ASCII'))
except:
print("Server nicht verfügbar\n\n")
我在服务器上逐行打印了 9 条消息。
实际的 GUI 是
import PySimpleGUI as sg
from pyzbar import pyzbar
import cv2
import os
import socket
import math
from time import time, sleep
from Crypto.Cipher import AES
H1 = 0
def read_qr():
vid = cv2.VideoCapture(0)
qr = False
while(not qr):
ret, frame = vid.read()
qr = pyzbar.decode(frame)
duration = .1
freq = 3000
os.system('play -nq -t alsa synth {} sine {}'.format(duration,freq))
qr = qr[0].data.decode().split(':::')
vid.release()
cv2.destroyAllWindows()
return qr
def si_msg(body):
global H1
H1 += 1
H2 = socket.gethostname().split('-')[2]
H3 = 0
H5, H4 = math.modf(time())
H6 = 2
H7 = len(body.encode('ASCII'))
si_msg = " ".join([str(H1), H2, str(H3), str(int(H4)), str(int(H5*10**8)), str(H6), str(H7), body])
return si_msg
def main():
sg.theme('PythonPlus')
status = 'Verbindung getrennt'
socket.setdefaulttimeout(2.5)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
layout = [ [sg.Text('Server-Adresse:'),sg.Input(key = 'k_server', default_text='192.168.1.40:9999')],
[sg.Button('Server bestätigen')],
[sg.Text('Status:'), sg.Text(status, key = 'k_status')],
[sg.Exit()]]
window = sg.Window('Virtueller Login', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
elif event == 'Server bestätigen':
status = 'Verbindung zum Server wird hergestellt'
window['k_status'].update(status)
server = values['k_server'].split(':')
try:
client.connect((server[0],int(server[1])))
status = 'Verbindung hergestellt: ausgeloggt'
window['k_status'].update(status)
except:
status = 'Verbindungsversuch fehlgeschlagen'
window['k_status'].update(status)
sg.popup('FEHLER: Server nicht gefunden. Bitte prüfen Sie die Adresse oder wenden Sie sich an den Administrator')
continue
window.start_thread(lambda: read_qr(), 'Code gefunden')
if event == 'Code gefunden':
qr = values[event][0]
msg = si_msg(qr)
print(msg)
client.send(msg.encode('ASCII'))
sleep(2)
client.close()
window.close()
if __name__ == '__main__':
main()
运行此主程序使我能够扫描二维码/条形码,该二维码/条形码已成功包装在标题中(我必须制作这个丑陋的东西)并在每次扫描时打印, H1
每次扫描时迭代扫描计数器。我在客户端或服务器上没有收到任何错误,但服务器只收到第一次扫描。
为了确保它与 pysimplegui 处理的多线程无关,我省略了以下行
window.start_thread(lambda: read_qr(), 'Code gefunden')
if event == 'Code gefunden':
qr = values[event][0]
msg = si_msg(qr)
print(msg)
client.send(msg.encode('ASCII'))
sleep(2)
并用直接扫描命令替换它们(冻结 GUI):
qr = read_qr()[0]
msg = si_msg(qr)
print(msg)
client.send(msg.encode('ASCII'))
这样我就可以启用连接、扫描代码、发送消息,然后循环似乎停止工作,我无法再扫描。我可以再次按下 GUI 的连接按钮,从而“重新连接”到服务器(从未断开连接?)再次扫描,但它不会向服务器发送消息,也不会第三次建立连接。
或者,简单地手动添加第二条消息也无法发送,这也不起作用:
qr = read_qr()[0]
msg = si_msg(qr)
print(msg)
client.send(msg.encode('ASCII'))
sleep(0.5)
msg = si_msg(qr)
print(msg)
client.send(msg.encode('ASCII'))
计数器迭代并打印,但没有发送第二条消息,连接似乎丢失,我可以重新连接,再次扫描(不发送任何消息),就是这样,再也没有第三次机会。
由于我没有收到任何错误,我对此有些困惑。我认为这与 pysimplegui 无关,因为连续的手动消息也没有发送,但我不知道,并乐意提供任何帮助...
-
在 Ubuntu 22.04 上使用 Tableau Server 时,MySQL ODBC 驱动程序出现问题。尝试连接导致错误:[unixODBC][驱动程序管理器]无法打开 lib'/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w...
在 Ubuntu 22.04 上使用 Tableau Server 时遇到 MySQL ODBC 驱动程序问题。尝试连接导致错误:
[unixODBC][Driver Manager]Can't open lib '/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so' : file not found
但文件存在:
tableau@tableau:/tmp$ namei /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so f: /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so d / d usr d lib d x86_64-linux-gnu d odbc - libmyodbc8w.so
最初系统安装在 AL2 上,使用 ODBC Mysql 驱动程序 5.xx Ofc,需要迁移。选择了 Ubuntu 22.04 LTS。驱动程序最初使用 8.2.x。
在 Tableau 开发人员的“帮助”下,它被降级到 8.0.x。
错误仍然存在。软件中似乎没有驱动程序调用的深度调试。问题肯定出在这里,因为没有尝试连接(根据转储)。
当前配置:
tableau@tableau:/tmp# cat /etc/odbc.ini [tableau] Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so Description = ODBC for MySQL SERVER = <my_server_replaced> PORT = <my_port_replaced> Database = <my_db_replaced> USER = <my_user_replaced> Password = <my_pwd_replaced>
tableau@tableau:/tmp# cat /etc/odbcinst.ini [MySQL ODBC 8.0 Unicode Driver] Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so SETUP=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8S.so UsageCount=1 [MySQL ODBC 8.0 ANSI Driver] Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so SETUP=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8S.so UsageCount=1
当前驱动程序:
tableau@tableau# apt info -a mysql-connector-odbc Package: mysql-connector-odbc Version: 8.0.33-1ubuntu22.04 Status: install ok installed Priority: optional Section: libs Maintainer: Oracle MySQL Product Engineering Team <[email protected]> Installed-Size: 23.4 MB Depends: dpkg-dev, mysql-community-client-plugins, debconf (>= 0.5) | debconf-2.0, libc6 (>= 2.34), libgcc-s1 (>= 3.0), libodbc2 (>= 2.3.1), libodbcinst2 (>= 2.3.1), libssl3 (>= 3.0.0~~alpha1), libstdc++6 (>= 11) Conflicts: mysql-connector-odbc-commercial Homepage: http://dev.mysql.com/downloads/connector/odbc/ Download-Size: unknown APT-Manual-Installed: yes APT-Sources: /var/lib/dpkg/status Description: MySQL ODBC driver This package allows you to connect to MySQL database servers using ODBC, the Open Database Connectivity abstraction layer which is understood by a variety of database tools that cannot talk to MySQL databases directly.
没有问题:
tableau@tableau:/tmp$ ldd -v /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so linux-vdso.so.1 (0x00007ffee2b70000) libssl.so.3 => /lib/x86_64-linux-gnu/libssl.so.3 (0x000073b38da27000) libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x000073b38cc00000) libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x000073b38da13000) libodbcinst.so.2 => /lib/x86_64-linux-gnu/libodbcinst.so.2 (0x000073b38d9fe000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x000073b38c800000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x000073b38d1e0000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000073b38c400000) /lib64/ld-linux-x86-64.so.2 (0x000073b38dad4000) libltdl.so.7 => /lib/x86_64-linux-gnu/libltdl.so.7 (0x000073b38d1d5000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000073b38d0ee000) Version information: /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so: libgcc_s.so.1 (GCC_3.0) => /lib/x86_64-linux-gnu/libgcc_s.so.1 ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2 libresolv.so.2 (GLIBC_2.9) => /lib/x86_64-linux-gnu/libresolv.so.2 libcrypto.so.3 (OPENSSL_3.0.0) => /lib/x86_64-linux-gnu/libcrypto.so.3 libstdc++.so.6 (GLIBCXX_3.4.20) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (CXXABI_1.3.8) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4.9) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (CXXABI_1.3.9) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4.29) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4.18) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4.11) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (CXXABI_1.3) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4.21) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (CXXABI_1.3.5) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4.15) => /lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 (GLIBCXX_3.4) => /lib/x86_64-linux-gnu/libstdc++.so.6 libssl.so.3 (OPENSSL_3.0.0) => /lib/x86_64-linux-gnu/libssl.so.3 libc.so.6 (GLIBC_2.28) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.33) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.34) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libssl.so.3: libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 libcrypto.so.3 (OPENSSL_3.0.3) => /lib/x86_64-linux-gnu/libcrypto.so.3 libcrypto.so.3 (OPENSSL_3.0.0) => /lib/x86_64-linux-gnu/libcrypto.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3: libc.so.6 (GLIBC_2.15) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.25) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.33) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.17) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.16) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.34) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libresolv.so.2: libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.34) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libodbcinst.so.2: libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libstdc++.so.6: libm.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libm.so.6 ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2 libgcc_s.so.1 (GCC_4.2.0) => /lib/x86_64-linux-gnu/libgcc_s.so.1 libgcc_s.so.1 (GCC_3.4) => /lib/x86_64-linux-gnu/libgcc_s.so.1 libgcc_s.so.1 (GCC_3.3) => /lib/x86_64-linux-gnu/libgcc_s.so.1 libgcc_s.so.1 (GCC_3.0) => /lib/x86_64-linux-gnu/libgcc_s.so.1 libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.6) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.33) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.25) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.18) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.16) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.32) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.17) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3.2) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.34) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libgcc_s.so.1: libc.so.6 (GLIBC_2.35) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.34) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6: ld-linux-x86-64.so.2 (GLIBC_2.2.5) => /lib64/ld-linux-x86-64.so.2 ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2 ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/libltdl.so.7: libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.34) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libm.so.6: ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2 libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6 libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6
tableau@tableau:/tmp$ isql -v tableau +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+
AppArmor:尝试完全禁用->结果相同。日志中没有拒绝它。因此保持“原样”。
将不胜感激任何提示或帮助!