@Pedro Junqueira I'm glad to see you were able to resolve your issue.
Thanks for posting your solution so that others experiencing the same thing can easily reference this. Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer.
Issue:
You have a Python QueueTrigger Function app which is not able to read the new message in the queue and you are getting the error Message has reached MaxDequeueCount of 5. Moving message to queue.
Resolution:
The above error message is completely misleading and has nothing to do with the encoding issue. The same has been already been reported to MSFT as a bug.
You got the right code from this stackoverflow post.
Here is the code that you have used and it is working when sending the message to be then able to get the message using function trigger.
from azure.storage.queue import (
QueueClient,
BinaryBase64EncodePolicy,
BinaryBase64DecodePolicy
)
queue_client = QueueClient.from_connection_string(
connection_string,
queue_name
)
# Setup Base64 encoding and decoding functions
queue_client.message_encode_policy = BinaryBase64EncodePolicy()
queue_client.message_decode_policy = BinaryBase64DecodePolicy()
for i in range(10):
print(f'Sending message {i}')
message = {'id': i, 'message' :'Hello World'}
message_string = json.dumps(message)
message_bytes = message_string.encode('utf-8')
queue_client.send_message(
queue_client.message_encode_policy.encode(content=message_bytes)
)