Skip to main content



      Home
Home » Eclipse Projects » Paho » MQTT over Websockets - status code 302 redirect ?(Does Paho Client obey Websockets http status code 302 to redirect?)
MQTT over Websockets - status code 302 redirect ? [message #1855906] Wed, 09 November 2022 06:19 Go to next message
Eclipse UserFriend
Hi, all!

I am trying connect to websocket URL which does http code 302 redirect to another location.

Should this be working and it is supported by Paho client?
Re: MQTT over Websockets - status code 302 redirect ? [message #1855967 is a reply to message #1855906] Sat, 12 November 2022 12:09 Go to previous message
Eclipse UserFriend
Hi!

I've been doing some tests and I can't get redirects to work.

My section of the code is as follows:

mqttc = mqtt.Client(client_id="pythonclient", transport='websockets')
mqttc.ws_set_options(path="/ws")

mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe

mqttc.connect("127.0.0.1", 8888, 60)


When on IP 127.0.0.1, port 8888 is listening mosquitto mqtt websocket server, everythink is working fine.
WHhen on IP 127.0.0.1, port 8888 is listening some other webserver (nginx for exxample) , which does HTTP redirect like this (yes, mqtt websockets are exposed this time on port 9001)

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: ws://localhost:9001/ws
Date: Sat, 12 Nov 2022 17:04:16 GMT

I get an error:
raise WebsocketConnectionError("WebSocket handshake error")
paho.mqtt.client.WebsocketConnectionError: WebSocket handshake error

---------------

My conclusion is, that paho mqtt client does not follow HTTP 30x redirects, which should by the RFC6455 written below or I don't know how to instruct it to follow redirects.

Can you please help me with that.
============================
RFC 6455 The WebSocket Protocol December 2011

1. If the status code received from the server is not 101, the
client handles the response per HTTP [RFC2616] procedures. In
particular, the client might perform authentication if it
receives a 401 status code; the server might redirect the client
using a 3xx status code (but clients are not required to follow
them), etc. Otherwise, proceed as follows.

[Updated on: Sat, 12 November 2022 12:12] by Moderator

Previous Topic:How to connect to a digitransit broker using paho mqtt client
Next Topic:Internet Loss for Gateway connected to Large Thread Network
Goto Forum:
  


Current Time: Fri Jun 20 22:32:43 EDT 2025

Powered by FUDForum. Page generated in 0.04644 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top