简体   繁体   English

Python Pika与TLSv1_2的连接

[英]Python Pika connection with TLSv1_2

I am using Python3.6 to get connection to RabbitMQ. 我正在使用Python3.6来连接RabbitMQ。 This connection uses TLSv1.2 protocol. 此连接使用TLSv1.2协议。 Setting the connection parameters for SSL: 设置SSL的连接参数:

    cxt = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    ssl_options = pika.SSLOptions(context=cxt, server_hostname=rabbit_config['HOST'])

    conn_params = pika.ConnectionParameters(port=rabbit_config['PORT'],
                                            ssl_options=ssl_options,
                                            credentials=creds,
                                            virtual_host=rabbit_config['VIRTUAL_HOST'],
                                            channel_max=channel_size,
                                            heartbeat=heart_beat)

Getting following error when connecting to rabbitMq: 连接到rabbitMq时出现以下错误:

AMQPConnectionError: (AMQPConnectorSocketConnectError: ConnectionRefusedError(61, 'Connection refused'),)

I have referred pika docs for Connection Parameters , and TLS params example , but no success so far. 我已经参考了连接参数TLS参数示例的 pika文档,但到目前为止还没有成功。

The similar code to connect to same Rabbit host is woriking in Java: 连接到同一个Rabbit主机的类似代码在Java中令人担忧:

    @Bean
    CachingConnectionFactory connectionFactory(String host,
            Integer port, String username,
            String password, boolean ssl,
             String sslAlgorithm) throws KeyManagementException, NoSuchAlgorithmException {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(host);
        connectionFactory.setPort(port);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        if (ssl) {
          connectionFactory.useSslProtocol();
          connectionFactory.useSslProtocol(sslAlgorithm);
        }

        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);
        cachingConnectionFactory.setRequestedHeartBeat(50);
        cachingConnectionFactory.setChannelCacheSize(10);
        return cachingConnectionFactory;
    }

I have a good idea why this must be happening, I am in a similar situation. 我很清楚为什么会这样,我处于类似的情况。 If you run your code on the same instance as the rabbitmq server, does it work? 如果您在与rabbitmq服务器相同的实例上运行代码,它是否有效? When using SSL over python it seems to be using the "guest" user and so it doesn't allow any connections outside of localhost. 在python上使用SSL时,似乎使用“guest”用户,因此它不允许在localhost之外进行任何连接。 If this is the case, have a look and try running it on the same instance. 如果是这种情况,请查看并尝试在同一实例上运行它。 It should work. 它应该工作。 If you click here you can have a look at my problem which is quite similar, and I have got it working on localhost. 如果你点击这里你可以看看我的问题非常相似,我已经在localhost上工作了。 My problem persists when trying to use it from outside the localhost. 尝试从localhost外部使用它时,我的问题仍然存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pika-处理RabbitMQ连接丢失 - Pika - Handling RabbitMQ Connection Loss 鼠兔连接丢失错误:pika.exceptions.StreamLostError: Stream 连接丢失:ConnectionResetError(104, 'Connection reset by peer') - Pika connection lost Error: pika.exceptions.StreamLostError: Stream connection lost: ConnectionResetError(104, 'Connection reset by peer') RabbitMQ Pika connection reset , (-1, ConnectionResetError(104, 'Connection reset by peer')) - RabbitMQ Pika connection reset , (-1, ConnectionResetError(104, 'Connection reset by peer')) 如何使用Pika和Python检查RabbitMQ中是否没有消息 - How to check if there is no message in RabbitMQ with Pika and Python 运行2天后,aio_pika出现随机连接错误 - Random connection errors with aio_pika after 2 days of running 是否可以在python 3.2.5中使用PROTOCOL_TLSv1_2? - Is it possible to use PROTOCOL_TLSv1_2 in python 3.2.5? 关闭/修改来自 FASTAPI 端点的现有 aio_pika 连接 - Close/modify an existing aio_pika connection from a FASTAPI endpoint Python模拟:修补Python Pika的“ basic_publish”功能 - Python mocking: Patching Python Pika's “basic_publish” function (安装Python 3.6.1)SSLError:SSL:TLSV1_ALERT_UNKNOWN_CA tlsv1 alert unknown ca - (Installing Python 3.6.1) SSLError: SSL: TLSV1_ALERT_UNKNOWN_CA tlsv1 alert unknown ca Python pika - 发布到不存在的交换不会引发异常 - Python pika - Publishing to non-existing exchange does not raise exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM