micropython / micropython/micropython-lib

umqtt.simple/umqtt/simple.py MQTTClient.publish() breaks on unicode

Open
#1,073 3 comments 0 reactions 1 assignee View on GitHub

@Josverl is already working on this.

Since Mar 9, 2026.

unicode
Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

I've been looking over this for a couple of weeks, and I'm struggling to find the underlying issue.

On a live MQTT session (I'm running from a RP2040 to a Mosquitto server), a mq.publish with a unicode character will break the session, eventually resulting in a Errno 104 / ECONNRESET (presumably when the input buffer is full).

The more "obvious" way to observe it is to do a mosquitto_sub on the topic, and the publish method stops transmitting data.

To observe:

mosquitto_sub -h yourserver -t homeassistant/sensor/bedroom/# -v

From a micropython:

mq.publish('homeassistant/sensor/bedroom/mytest', 'F') # works fine
mq.publish('homeassistant/sensor/bedroom/mytest' '°F') # \u0080 followed by F, appears to work
mq.publish('homeassistant/sensor/bedroom/mytest', 'F') # no data is received

subsequent/enough further publish() calls will result in the ECONNRESET

Testing against mosquitto_pub with the same topic and unicode message indicate it all works.

Somehow I think the length calculation is thrown off by the string-vs-bytes-vs-unicode thing, but haven't been able to nail it down yet.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.