For security reasons, passwords often include special characters such as punctuation. But when using RabbitMQ with Celery, a password containing characters like ? can break broker URL parsing.
Suppose we want to connect to a RabbitMQ server with username admin and password mypass?1234. A broker URL might look like this:
1 | amqp://admin:mypass?1234@test.knktc.com// |
And the Celery code might look like this:
1 | from celery import Celery |
Running that code produces an error like this:
1 | ValueError: invalid literal for int() with base 10: 'mypass' |
The problem is that the ? in the password is being interpreted as part of the URL syntax.
The solution is to URL-encode the password first:
1 | from celery import Celery |
After that, the connection works normally.