🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

Python connect to Solace PubSub+ OAuth2.0

Shijo
Shijo Member Posts: 10 ✭✭
Here is my code snippet
```
import solace.messaging.messaging_service as service
from solace.messaging.publisher.outbound_message import OutboundMessageBuilder
from solace.messaging.publisher.persistent_message_publisher import Topic

broker_props = {"solace.messaging.transport.host": "tcps://mr-dfdsffdrd.messaging.solace.cloud:54434",
"solace.messaging.service.vpn-name": "test-service",
}

authentication_strategy = OAuth2.of(token, None, "OKTA AUTH URI")

messaging_service = MessagingServiceClientBuilder().from_properties(configuration=properties).\
with_authentication_strategy(authentication_strategy=authentication_strategy).build()
messaging_service.connect()
print("connected")
```

After running the code, i am getting error:

```
2024-01-12 10:21:39,328 [DEBUG] solace.messaging.connections: [messaging_service.py:1613] [MessagingServiceClientBuilder] initialized
2024-01-12 10:21:39,328 [DEBUG] solace.messaging.connections: [messaging_service.py:1649] [MessagingService] with authentication strategy
2024-01-12 10:21:39,329 [DEBUG] solace.messaging.connections: [messaging_service.py:1748] Build [MessagingService]
2024-01-12 10:25:17,249 [WARNING] solace.messaging.core: [_solace_session.py:821] [[SERVICE: 0x114190760] - [APP ID: mbo-mpl-client]] SOLCLIENT_SUBCODE_FAILED_LOADING_TRUSTSTORE
2024-01-12 10:25:17,249 [WARNING] solace.messaging.core: [_solace_session.py:823] [[SERVICE: 0x114190760] - [APP ID: mbo-mpl-client]] SESSION CREATION UNSUCCESSFUL. Failed to load trust store.
```

I am not getting why this session creation is unsuccessfull.
TLS security is mandatory for the message service?
The connections are working with the same configuration in Java spring.
Can anybody help on this?

Comments

  • Shijo
    Shijo Member Posts: 10 ✭✭

    The problem was resolved, by updating the broker properties. Below is the complete code snippet:

    SOLACE_BROKER_PROPERTIES = {
        "solace.messaging.transport.host": "tcps://mr-con-4fg4fdgfd.msg.solace.cloud:55443",
        "solace.messaging.service.vpn-name": "test-vpn",
        "solace.messaging.authentication.oauth2.issuer-identifier":
            "OKTA_ISSUER",
        "solace.messaging.tls.cert-validated": False,
        "solace.messaging.tls.cert-validated-date": False,
    }
    …
    …
    token = "TOKEN"
    authentication_strategy = OAuth2.of(token, None, "issuer identifier")
    self.messaging_service = MessagingServiceClientBuilder().from_properties(configuration=SOLACE_BROKER_PROPERTIES).\
            with_authentication_strategy(authentication_strategy=authentication_strategy).\
            build()
    self.messaging_service.connect()