# python using tls : error connecting to a Solace pubsub broker

**URL:** <https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777>\
**Category:** General Discussions\
**Created:** [October 7, 2023, 2:14pm UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777 "2023-10-07T14:14:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![coz787](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/coz787/32/363_2.png) [@coz787](https://community.solace.com/u/coz787)\
**Post date:** [October 7, 2023, 2:14pm UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/1 "2023-10-07T14:14:35Z")

</div>

```php
# Broker Config
broker_props = {
    # "solace.messaging.application_id" : "default", 
    "solace.messaging.transport.host": os.environ.get('SOLACE_HOST') or "tcps://pubsub.preops.nm.eurocontrol.int:5671",
   
    "solace.messaging.service.vpn-name": os.environ.get('SOLACE_VPN') or "",
    "solace.messaging.authentication.scheme.basic.username": os.environ.get('SOLACE_USERNAME') or " ********",
    "solace.messaging.authentication.scheme.basic.password": os.environ.get('SOLACE_PASSWORD') or " ********"
    }
strustedstore= os.environ['HOME']+"/dev/solace-samples-python/howtos/fixtures"
strustedstore= os.environ['HOME'] + "/nm_store"
strustedstore= "/etc/ssl/certs"
transport_security = TLS.create() \
.with_certificate_validation(True, validate_server_name=True,
                             trust_store_file_path=strustedstore )
# .without_certificate_validation()
# trust_store_file_path=SamplerUtil.get_trusted_store_dir())

occauth= ClientCertificateAuthentication.of(certificate_file=smycrt,\
                                            key_file=smykey ,\
                                            key_password=None )
# Build A messaging service with a reconnection strategy of 20 retries over an interval of 3 seconds
# Note: The reconnections strategy could also be configured using the broker properties object
messaging_service = MessagingService.builder().from_properties(broker_props)\
                    .with_reconnection_retry_strategy(RetryStrategy.parametrized_retry(20,3))\
                    .with_transport_security_strategy(transport_security) \
                    .with_authentication_strategy(occauth) \
                    .build()
print("messaging_service",messaging_service)
# Blocking connect thread
messaging_service.connect()

```

Hello, my code just above ; and the error that i have :

```lua

{'solace.messaging.transport.host': 'tcps://pubsub.preops.nm.eurocontrol.int:5671', 
'solace.messaging.service.vpn-name': '', 
'solace.messaging.authentication.scheme.basic.username': ' ********', 
'solace.messaging.authentication.scheme.basic.password': ' ********', 
'solace.messaging.transport.reconnection-attempts': 20, 
'solace.messaging.transport.reconnection-attempts-wait-interval': 3, 
'solace.messaging.tls.cert-validated': True, 
'solace.messaging.tls.cert-reject-expired': False, 
'solace.messaging.tls.cert-validate-servername': True, 
'solace.messaging.tls.trust-store-path': '/etc/ssl/certs', 
'solace.messaging.authentication.scheme': 'AUTHENTICATION_SCHEME_CLIENT_CERTIFICATE',
'solace.messaging.authentication.client-cert.private-key-password': None, 
'solace.messaging.authentication.client-cert.private-key-file': '/home/pavet/.nmcert/key.pem', 
'solace.messaging.authentication.client-cert.file': '/home/pavet/.nmcert/crt.pem'}
cs 0
messaging_service application_id : gitana/29418/00000001/Y83XXFfUui connected : False
2023-10-07 16:10:07,124 [WARNING] solace.messaging.core: [_solace_session.py:950] [[SERVICE: 0x7f6e47017f70] - [APP ID: gitana/29418/00000001/Y83XXFfUui]] {'caller_description': 'do_connect', 'return_code': 'Not ready', 'sub_code': 'SOLCLIENT_SUBCODE_PROTOCOL_ERROR', 'error_info_sub_code': 8, 'error_info_contents': "ClientdataParser: Bad SMF version of 1 when last/everReadMoreThanOne=0/0in session state 'CONNECTING': client name 'gitana/29418/00000001/Y83XXFfUui', peer host 'tcps://pubsub.preops.nm.eurocontrol.int:5671' address 'IP 193.58.21.120', connection 'tcps_Tx"}
2023-10-07 16:10:07,126 [WARNING] solace.messaging.connections: [messaging_service.py:1164] [[SERVICE: 0x7f6e47017f70] - [APP ID: gitana/29418/00000001/Y83XXFfUui]] Connection failed. Status code: 3
Traceback (most recent call last):
File "./howto40_solace_reader_r01.py", line 119, in <module>
messaging_service.connect()
File "/home/pavet/py3std/lib/python3.8/site-packages/solace/messaging/messaging_service.py", line 1165, in connect
raise error
solace.messaging.errors.pubsubplus_client_error.PubSubPlusCoreClientError: {'caller_description': 'do_connect', 'return_code': 'Not ready', 'sub_code': 'SOLCLIENT_SUBCODE_PROTOCOL_ERROR', 'error_info_sub_code': 8, 'error_info_contents': "ClientdataParser: Bad SMF version of 1 when last/everReadMoreThanOne=0/0in session state 'CONNECTING': client name 'gitana/29418/00000001/Y83XXFfUui', peer host 'tcps://pubsub.preops.nm.eurocontrol.int:5671' address 'IP 193.58.21.120', connection 'tcps_Tx"}

```

I would be greatful if an expert could help me … k.regards

---

<div class="post-metadata">

**Author:** ![emilzegers](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/emilzegers/32/344_2.png) [@emilzegers](https://community.solace.com/u/emilzegers)\
**Post date:** [October 9, 2023, 8:33pm UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/2 "2023-10-09T20:33:19Z")

</div>

Hi Didier,

Thanks for posting to the Solace Community forum. I’m not sure I’m the right expert here but will try to help anyway 🙂  
Looks like the (tls) connection is not established properly? Does the messaging\_service.connect() run successfully, can you test that?

In the code I see solace.messaging.transport.host can either pick an environment variable and if not set fall back to a default hardcoded host name. In this case it is ‘tcps://pubsub.preops.nm.eurocontrol.int:5671’ address ‘IP 193.58.21.120’. Is that the expected value for the host? Would be useful to check if the service is up and reachable on the IP address mentioned. Also the VPN value seems to be empty, is that expected?

The description for ‘sub\_code’: ‘SOLCLIENT\_SUBCODE\_PROTOCOL\_ERROR’ is:  
‘An API call failed due to a protocol error with the broker (not an application fault).’

By default port 5671 is AMQP TLS / SSL. Is this AMQP TLS port enabled on the broker, assuming you want to connect using TLS? Are you working against a software broker or appliance?

More questions than answers maybe, but hopefully it helps you to check some settings and find the right direction.

Regards,

Emil

---

<div class="post-metadata">

**Author:** ![coz787](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/coz787/32/363_2.png) [@coz787](https://community.solace.com/u/coz787)\
**Post date:** [October 10, 2023, 2:22pm UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/3 "2023-10-10T14:22:19Z")

</div>

Hello & thank you Emil,

The amqps software broker ( and it is a Solace pubsub+ instance) is functional. I have another python tool - using qpid::proton capable to consume its messages and it works.

You are right : messaging\_service.connect() raises an exception . What’s strikes me is this part .

```ada

'return_code': 'Not ready', 'sub_code': 'SOLCLIENT_SUBCODE_PROTOCOL_ERROR', 'error_info_sub_code': 8, 'error_info_contents': "ClientdataParser: Bad SMF version of 1 when last/everReadMoreThanOne=0/0in session state 'CONNECTING': client name 'gitana/29418/00000001/Y83XXFfUui',

```

Best regards . Didier

---

<div class="post-metadata">

**Author:** ![emilzegers](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/emilzegers/32/344_2.png) [@emilzegers](https://community.solace.com/u/emilzegers)\
**Post date:** [October 11, 2023, 11:09am UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/4 "2023-10-11T11:09:27Z")

</div>

Bit of a guess but could this be due to a version mismatch between the Python solace-pubsubplus module and the broker? What versions do you use on either side?

---

<div class="post-metadata">

**Author:** ![Ragnar](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/ragnar/32/180_2.png) [@Ragnar](https://community.solace.com/u/Ragnar)\
**Post date:** [October 12, 2023, 9:06pm UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/5 "2023-10-12T21:06:58Z")

</div>

The PubSub+ Messaging API for Python that you are using is an SMF (Solace Message Format) API. SMF is a Solace proprietary messaging protocol the comes with advantages when connecting to Solace brokers.

Solace brokers also support AMQP and MQTT if you want to use a open standard messaging protocol. In those cases you should use an AMQP API such as qpid::proton. There is no need to use a Solace API for open standard messaging protocols as there are many implementations to choose from.

There error you are seeing is simply the API expects SMF and is getting back AMQP.  
The default port for SMF is ‘55555’ but this often is changed by the network administration and you should consult with your solace administrator for the appropriate port to use for SMF.

---

<div class="post-metadata">

**Author:** ![coz787](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/coz787/32/363_2.png) [@coz787](https://community.solace.com/u/coz787)\
**Post date:** [October 14, 2023, 2:57pm UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/6 "2023-10-14T14:57:43Z")

</div>

Hello Ragnar, thank you . I confirm your analysis and my misunderstanding about the nature of the protocol. In fact, i use yet qpid::proton in Python but … find it quite cumbersome to deploy …

and so i am searching a python library capable of amqp 1.0 mostly as a listener / reader . That’s why i gave a glance to solace pub/sub+ … I you have some ideas. Best regards

---

<div class="post-metadata">

**Author:** ![emilzegers](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/emilzegers/32/344_2.png) [@emilzegers](https://community.solace.com/u/emilzegers)\
**Post date:** [October 16, 2023, 9:03am UTC](https://community.solace.com/t/python-using-tls-error-connecting-to-a-solace-pubsub-broker/1777/7 "2023-10-16T09:03:44Z")

</div>

Hi Didier, there are some repositories with examples at

> **[Solace Samples](https://github.com/orgs/SolaceSamples/repositories?q=amqp&type=all&language=&sort=)**
>
> This repository contains samples for developers to learn how to use the Solace APIs - Solace Samples

Did you already look at these? Also

> **[Home](https://www.solace.dev/)**
>
> Create event-driven apps and microservices on any platform with whatever language, open protocols, and APIs you choose.

might have some useful information.
