Hi Solace Community,
I have a strange issue with the Python API - or I might just be dumb right now
I’ve started with a pretty simple script that connects to a broker and just reports the client id and disconnects. (removed sensitive values…)
from solace.messaging.messaging_service import MessagingService, RetryStrategy
from solace.messaging.config.authentication_strategy import BasicUserNamePassword
from solace.messaging.config.transport_security_strategy import TLS
def main():
broker_props = {"solace.messaging.transport.host": "tcps://myhost",
"solace.messaging.service.vpn-name": "myvpn"}
transport_security = TLS.create().without_certificate_validation()
messaging_service = MessagingService.builder() \
.from_properties(broker_props) \
.with_authentication_strategy(BasicUserNamePassword("username", "*****")) \
.with_connection_retry_strategy(RetryStrategy.forever_retry(10000)) \
.with_reconnection_retry_strategy(RetryStrategy.forever_retry(10000)) \
.with_transport_security_strategy(transport_security) \
.build()
messaging_service.connect()
if messaging_service.is_connected:
print(messaging_service.get_application_id())
messaging_service.disconnect()
if __name__ == "__main__":
main()
My project structure looks pretty simple (I’m using activated venv):
.venv
receive_events.py
And when I run this script with my virtualenv enabled I get this:
app_8a54949a-e460-4e0b-bce0-354743572c53
So the script is working fine, Solace API seems to be installed correctly in my .venv aso…
Now let’s move the script to a subfolder like src
.venv
src/
receive_events.py
When I run python src/receive_events.py
or cd into src
and then run python receive_events.py
I get
Traceback (most recent call last):
File "src/receive_messages.py", line 1, in <module>
from solace.messaging.messaging_service import MessagingService, RetryStrategy
ModuleNotFoundError: No module named 'solace.messaging'
I tried out setting PYTHONPATH
to different values - but no luck.
which python
.venv/bin/python
find .venv | grep solace/messaging/__init__
.venv/lib/python3.8/site-packages/solace/messaging/__init__.py
I’m using solace_pubsubplus-1.2.1
Sorry, but I’m lost
I’haven’t had any issues with other libraries - in fact src/
contains a Django App where I wanted Solace to connect with…