Authentication Error - using pika from python

369 views
Skip to first unread message

Sundeep Oberoi

unread,
Jan 12, 2021, 4:45:02 AM1/12/21
to rabbitmq-users
I am facing a puzzling (to me) problem. I have a simple sender 

program written in python that uses pika to send data to 

rabbitmq. When I start rabbitmq with no rabbitmq.conf file this 

sender program works fine both with the guest user and a user 

created in rabbitmq with a password. The code of the simple 

sender is below

---------------------------------------------------

[centos@mqserver authtest]$ cat send.py
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters

(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

with open("inputdata.txt", "r") as infile:
     for line in infile:
        print(line)
        channel.basic_publish(exchange='', routing_key='hello', 

body= line)
infile.close()

connection.close()

---------------------------------------------------

The input data file is

-------------------------------
[centos@mqserver authtest]$ cat inputdata.txt
line 1
line 2
line 3

-------------------------------

When I run this it runs as expected and I see the following 

output on screen and a consumer is able to consume these three 

strings

--------------------------------

line 1

line 2

line 3
--------------------------------

Now when I stop rabbitmq-server and start it with the following 

rabbitmq.conf file

--------------------------
[centos@mqserver authtest]$ cat /etc/rabbitmq/rabbitmq.conf
auth_mechanisms.1 = PLAIN
auth_mechanisms.1 = AMQPLAIN
--------------------------


When I run the simple sender with guest user I get a 

pika.exceptions.AuthenticationError: PLAIN as shown below


[centos@mqserver authtest]$ python send.py
Traceback (most recent call last):
  File "send.py", line 3, in <module>
    connection = pika.BlockingConnection

(pika.ConnectionParameters(host='localhost'))
  File "/usr/lib/python2.7/site-

packages/pika/adapters/blocking_connection.py", line 359, in 

__init__
    self._impl = self._create_connection(parameters, 

_impl_class)
  File "/usr/lib/python2.7/site-

packages/pika/adapters/blocking_connection.py", line 450, in 

_create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AuthenticationError: PLAIN
[centos@mqserver authtest]$


When I run this same simple sender with an user that has been 

created in Rabbitmq with a password, I get the same error as 

shown below


[centos@mqserver authtest]$ python sendwithuser.py
Traceback (most recent call last):
  File "sendwithuser.py", line 5, in <module>
    connection = pika.BlockingConnection(parameters)
  File "/usr/lib/python2.7/site-

packages/pika/adapters/blocking_connection.py", line 359, in 

__init__
    self._impl = self._create_connection(parameters, 

_impl_class)
  File "/usr/lib/python2.7/site-

packages/pika/adapters/blocking_connection.py", line 450, in 

_create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AuthenticationError: PLAIN



What could be the reason for this? 

Thế Vỹ Hồng

unread,
Jan 12, 2021, 10:46:21 AM1/12/21
to rabbitm...@googlegroups.com
Haven't tried it yet. But I think your conf should be

```
auth_mechanisms.1 = PLAIN
auth_mechanisms.2 = AMQPLAIN
```
(Note the number)

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/8760bcf2-6065-43cc-b661-a91c15cff266n%40googlegroups.com.

Sundeep Oberoi

unread,
Jan 12, 2021, 12:08:41 PM1/12/21
to rabbitmq-users
I am now using the following configuration file

----------------------------------------------------------------------------------------------------------------------
listeners.ssl.default = 5671

ssl_options.cacertfile = /etc/rabbitmq/QuantairaCA-cert.pem
ssl_options.certfile   = /etc/rabbitmq/mqserver-cert.pem
ssl_options.keyfile    = /etc/rabbitmq/mqserver-key.pem
ssl_options.verify     = verify_peer
ssl_options.fail_if_no_peer_cert = false

auth_backends.1 = internal
auth_backends.2 = internal
auth_backends.3 = rabbitmq_auth_mechanism_ssl

auth_mechanisms.1 = PLAIN
auth_mechanisms.2 = AMQPLAIN
auth_mechanisms.3 = EXTERNAL

ssl_cert_login_from = common_name

-------------------------------------------------------------------------------------------------

Now I run send.py which uses just the guest user and none of the ssl stuff but I get the following error

$python send.py

Traceback (most recent call last):
  File "send.py", line 3, in <module>
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 359, in __init__
    self._impl = self._create_connection(parameters, _impl_class)
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.exceptions.ProbableAuthenticationError: StreamLostError: ("Stream connection lost: error(104, 'Connection reset by peer')",)

Luke Bakken

unread,
Jan 12, 2021, 12:48:05 PM1/12/21
to rabbitmq-users
Hello,

Please note that you must configure TLS correctly in your Pika application - https://github.com/pika/pika/blob/master/docs/examples/tls_mutual_authentication.rst

Thanks,
Luke

Reply all
Reply to author
Forward
0 new messages