<p>In Kubernetes I have deployed RabbitMQ pod, service and ingress.
I have access to RabbitMQ UI and I added a user that has access to virtual host &quot;/&quot; and a password.</p>
<p>I tried to create a Python pod that connects to RabbitMQ and create a queue but I have the following error:</p>
<pre><code>Traceback (most recent call last):
  File &quot;/dump_notify/producer.py&quot;, line 40, in &lt;module&gt;
    main()
  File &quot;/dump_notify/producer.py&quot;, line 24, in main
    connection = pika.BlockingConnection(parameters)
  File &quot;/opt/app-root/lib64/python3.8/site-packages/pika/adapters/blocking_connection.py&quot;, line 360, in __init__
    self._impl = self._create_connection(parameters, _impl_class)
  File &quot;/opt/app-root/lib64/python3.8/site-packages/pika/adapters/blocking_connection.py&quot;, line 451, in _create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
</code></pre>
<p>My Python code is this:</p>
<pre><code>import pika
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class FileEventHandler(FileSystemEventHandler):
    def __init__(self, channel):
        self.channel = channel

    def on_created(self, event):
        if not event.is_directory:
            self.channel.basic_publish(exchange='', routing_key='myqueue',
                                        body='New file has been added to SFTP : %s' % event.src_path)

def main():
    credentials = pika.PlainCredentials('Lbeodeobf', 'test')
    print('Logged')

    parameters = pika.ConnectionParameters('X',
                                   5672,
                                   '/',
                                   credentials)
    print(parameters)

    connection = pika.BlockingConnection(parameters)
    print(&quot;Connection...&quot;)
    channel = connection.channel()

    channel.queue_declare(queue='myqueue')

    event_handler = FileEventHandler(channel)

    observer = Observer()
    observer.schedule(event_handler, path='/mnt/', recursive=False)
    observer.start()
    observer.join()

if __name__ == &quot;__main__&quot;:
    main()
</code></pre>
<p>Where can I be wrong ?</p>

jos97
<p>As you are getting  <code>pika.exceptions.AMQPConnectionError</code> is not related to python code which you run, this is related to the connection error for  RabbitMQ.  So,  you need to install <a href="https://www.rabbitmq.com/download.html" rel="nofollow noreferrer">RabbitMQ</a> on your PC or server . Post successful installation if it is a linux server then  run this commands <code>sudo systemctl start rabbitmq-server</code> and <code>sudo systemctl enable rabbitmq-server</code>  which will start and enable the rabbit server and then run the python code which may resolve your issue.</p>
