Python Socketio Client hat einen Transportfehler durch Verbindung mit Flask-Socketio-Server nur auf Raspberry Pi 5Python

Python-Programme
Anonymous
 Python Socketio Client hat einen Transportfehler durch Verbindung mit Flask-Socketio-Server nur auf Raspberry Pi 5

Post by Anonymous »

Ich möchte meinen Raspberry Pi 5-Anschluss an einen Python-Socketio-Client anschließen, um meinen Flask-Socketio-Server auf einem anderen Gerät zu verbinden. Ich verwende einen Nginx als WebSocket -Reverse -Proxy. Ich habe die Internetverbindung überprüft, aber ich konnte keine Verbindungsprobleme finden und konnte keinen Unterschied zwischen einer LAN- und WLAN -Verbindung erkennen. Das Seltsame ist, dass, wenn ich denselben Code auf meinem Windows -PC verwende, ein Problem ausgelöst hat. Der Server wurde nur für iOS -Apps zu meinem Raspberry Pi 5 hinzugefügt und hat auch gut funktioniert. Was könnte das Problem sein oder was kann ich tun, um das Problem besser zu identifizieren?

Code: Select all

 Received packet PING data
[INFO   ] Received packet PING data
Sending packet PONG data
[INFO   ] Sending packet PONG data
WebSocket connection was closed, aborting
[WARNING] WebSocket connection was closed, aborting
Waiting for write loop task to end
[INFO   ] Waiting for write loop task to end
Exiting write loop task
[INFO   ] Exiting write loop task
Engine.IO connection dropped
[INFO   ] Engine.IO connection dropped
[DISCONNECT]: reason: transport error
[DEBUG]: "transport error"
Connection failed, new attempt in 3.30 seconds
Exiting read loop task
[INFO   ] Connection failed, new attempt in 3.30 seconds
[INFO   ] Exiting read loop task
Attempting WebSocket connection to wss://www.mylink.de/socket.io/?transport=websocket&EIO=4
[INFO   ] [Attempting WebSocket connection to wss]//www.mylink.de/socket.io/?transport=websocket&EIO=4
WebSocket connection accepted with {'sid': 'dGtmnqUR9rU279m1AAAU', 'upgrades': [], 'pingTimeout': 20000, 'pingInterval': 25000, 'maxPayload': 1000000}
[INFO   ] [WebSocket connection accepted with {'sid'] 'dGtmnqUR9rU279m1AAAU', 'upgrades': [], 'pingTimeout': 20000, 'pingInterval': 25000, 'maxPayload': 1000000}
Engine.IO connection established
[INFO   ] Engine.IO connection established
Sending packet MESSAGE data 0{}
[INFO   ] Sending packet MESSAGE data 0{}
Received packet MESSAGE data 0{"sid":"sVrC7eaUscRr558dAAAV"}
[INFO   ] Received packet MESSAGE data 0{"sid":"sVrC7eaUscRr558dAAAV"}
Namespace / is connected
[INFO   ] Namespace / is connected
[INFO]: Verbunden mit dem Server.
Emitting event "test" [/]
[INFO   ] Emitting event "test" [/]
Sending packet MESSAGE data 2["test",{"Hallo":"World"}]
[INFO   ] Sending packet MESSAGE data 2["test",{"Hallo":"World"}]
Reconnection successful
[INFO   ] Reconnection successful
< /code>
Hier ist der Fehler auf meinem Server: < /p>
dkoIY3aUHWE7_HlkAAAS: Sending packet PING data None
dkoIY3aUHWE7_HlkAAAS: Received packet PONG data
dkoIY3aUHWE7_HlkAAAS: Sending packet PING data None
dkoIY3aUHWE7_HlkAAAS: Received packet PONG data
--------------------------------------------------------------------------------
[DISCONNECT]reason = transport close
[DISCONNECT] - traceback: NoneType: None
--------------------------------------------------------------------------------
dGtmnqUR9rU279m1AAAU: Sending packet OPEN data {'sid': 'dGtmnqUR9rU279m1AAAU', 'upgrades': [], 'pingTimeout': 20000, 'pingInterval': 25000, 'maxPayload': 1000000}
dGtmnqUR9rU279m1AAAU: Received request to upgrade to websocket
dGtmnqUR9rU279m1AAAU: Upgrade to websocket successful
dGtmnqUR9rU279m1AAAU: Received packet MESSAGE data 0{}
dGtmnqUR9rU279m1AAAU: Sending packet MESSAGE data 0{"sid":"sVrC7eaUscRr558dAAAV"}
Ein Client hat sich verbunden.
dGtmnqUR9rU279m1AAAU: Received packet MESSAGE data 2["test",{"Hallo":"World"}]
received event "test" from sVrC7eaUscRr558dAAAV [/]
dGtmnqUR9rU279m1AAAU: Sending packet PING data None
dGtmnqUR9rU279m1AAAU: Received packet PONG data
dGtmnqUR9rU279m1AAAU: Sending packet PING data None
dGtmnqUR9rU279m1AAAU: Received packet PONG data
dGtmnqUR9rU279m1AAAU: Sending packet PING data None
--------------------------------------------------------------------------------
[DISCONNECT]reason = transport close
[DISCONNECT] - traceback: NoneType: None

--------------------------------------------------------------------------------
dGtmnqUR9rU279m1AAAU: Received packet PONG data
gNo1jQEFB1pggf7-AAAW: Sending packet OPEN data {'sid': 'gNo1jQEFB1pggf7-AAAW', 'upgrades': [], 'pingTimeout': 20000, 'pingInterval': 25000, 'maxPayload': 1000000}
gNo1jQEFB1pggf7-AAAW: Received request to upgrade to websocket
gNo1jQEFB1pggf7-AAAW: Upgrade to websocket successful
gNo1jQEFB1pggf7-AAAW: Received packet MESSAGE data 0{}
gNo1jQEFB1pggf7-AAAW: Sending packet MESSAGE data 0{"sid":"p2sePiDTxpxpymyQAAAX"}
Ein Client hat sich verbunden.
gNo1jQEFB1pggf7-AAAW: Received packet MESSAGE data 2["test",{"Hallo":"World"}]
received event "test"  from p2sePiDTxpxpymyQAAAX [/]
gNo1jQEFB1pggf7-AAAW: Sending packet PING data None
gNo1jQEFB1pggf7-AAAW: Received packet PONG data
< /code>
Zuerst habe ich die Version von Flask und Flask_Socketio auf meinem Server und auf meinem Client von Python-Socketio [Client] überprüft und aktualisiert, dann habe ich den Code des Servers und des Clients auf eine "Verbindung" und "Abnahme" -Funktion reduziert. Hier ist der Code von meinem Client: < /p>
    def run_socketio_client(self):
client = SocketIOClient()
client.connect("https://www.mylink.de")  # Server-URL
client.wait()
< /code>
import socketio

class SocketIOClient:
def __init__(self):
self.sio = socketio.Client(
reconnection=True,
reconnection_delay=3,
reconnection_delay_max=10,
logger=True,
engineio_logger=True
)

# Events registrieren
self.sio.on('connect', self.on_connect)
self.sio.on('disconnect', self.on_disconnect)

def on_connect(self):
print("[INFO]: Verbunden mit dem Server.")
self.sio.emit("test", {"Hallo": "World"})

def on_disconnect(self, reason=None):
print("[DISCONNECT]: reason:", reason)

if reason == self.sio.reason.CLIENT_DISCONNECT:
print("[DEBUG]: CLIENT_DISCONNECT")
elif reason == self.sio.reason.SERVER_DISCONNECT:
print("[DEBUG]: SERVER_DISCONNECT")
elif reason == self.sio.reason.TRANSPORT_ERROR:
print("[DEBUG]: \"transport error\"")
else:
print('[DEBUG]: other reason:', reason)

def connect(self, url):
print("[INFO]: Verbindungsaufbau mit dem Server...")
self.sio.connect(
url,
transports=['websocket'],
wait_timeout=10,
retry=True
)

def wait(self):
self.sio.wait()
< /code>
and here from my server:
from flask import Flask, request
from flask_socketio import SocketIO, emit, join_room, leave_room, close_room, rooms, disconnect
import traceback

app = Flask(__name__)
socketio = SocketIO(app,
server=True,
logger=True,
engineio_logger=True,
cors_allowed_origins="*",
async_mode="gevent",
transports=["websocket"])

@socketio.on_error_default
def handle_error(e):
print(f"[ERROR] - error: {e}")
print("[ERROR] - handle_error traceback:")
print(traceback.format_exc())

# WebSocket: Verbindung hergestellt
@socketio.on('connect')
def handle_connect():
print('Ein Client hat sich verbunden.')

@socketio.on('disconnect')
def disconnect(reason=None):
#sid = request.sid
print("------------------------------------------------------------------------------")
print("[DISCONNECT]reason =", reason)
print("[DISCONNECT] - traceback:", traceback.format_exc())
print("------------------------------------------------------------------------------")

if __name__ == '__main__':
socketio.run(app, port=5000)
< /code>
Unfortunately the Raspberry still has regularly a transport error and my Windows program with the same code doesn't.
EDIT:
This is my first time working with Nginx, and I thought if the .conf works with Windows and iOS clients, it should work with my Raspberry Pi client too. But maybe that's where the problem is.  So here are my nginx.conf and mylink.conf in sites-enabled.
nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
worker_rlimit_nofile 3000000;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 2048;
multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
< /code>
this is my current(yesterday I used a different) mylink.conf:
server {
# Leite alle HTTP-Anfragen zu HTTPS weiter
listen 80 default_server;
server_name mylink.de www.mylink.de;
return 301 https://www.mylink.de$request_uri;
}

server {
listen 443 ssl;
server_name mylink.de www.mylink.de;

# SSL-Zertifikate
ssl_certificate /etc/letsencrypt/live/www.mylink.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.mylink.de/privkey.pem;

location / {
include proxy_params;
proxy_pass http://127.0.0.1:5000;
}

location /socket.io {
proxy_pass http://127.0.0.1:5000/socket.io;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Timeout-Einstellungen erhöhen
proxy_connect_timeout 3600s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_buffering off;

}

# static File
location /static/ {
root /var/www/mylink/static;
expires 30d;
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post