0

I've made a snippet to connect to a remote mqtt server that I do not administrate, I know the Java message is accepted but the python message isn't. Any idea? I'm not familiar with python byte stuff.

I do JSON > byte stuff

In Java I can send a message with payload in byte or bytearray enter image description here

But in Python, the message is received but the admin report broker error

`b'{\n  "subject": "subject1",\n  "date": "Wed, 17 Feb 2021 13:27:32 +0100"\n}'` to topic `testtopic/testchannel`

abc being my json.

>>> 'abc'.encode('utf-8') b'abc'

>>> bytearray('abc', 'utf-8') bytearray(b'abc')

400 Bad Request: [{"error":"BadRequest","description":"date has invalid format"}]

python3: bytes vs bytearray, and converting to and from strings

hardillb
  • 54,545
  • 11
  • 67
  • 105
Alsushi
  • 373
  • 3
  • 14
  • Please do NOT post images of text, they are really hard to read and impossible for people that need to use screen readers. – hardillb Apr 20 '21 at 10:35
  • Also update the question to show the actual code as described here: https://stackoverflow.com/help/minimal-reproducible-example – hardillb Apr 20 '21 at 10:38
  • For the code it's default python paho mqtt. I can't get access to the broker's code so there no reproducible example I'm afraid – Alsushi Apr 20 '21 at 11:15
  • No, you need to show us a LOT more of your code, in the context of how it's actually used. What you've supplied tells us nothing about how it's interacting with the Paho code. – hardillb Apr 20 '21 at 12:00

1 Answers1

0

Ok so obviously, the date error is actually a date type error

The type was enforced.

Conclusion all the payload format are working.

Alsushi
  • 373
  • 3
  • 14