Skip to content

Instantly share code, notes, and snippets.

@grawert
Created June 7, 2016 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grawert/d7ea0041b72b82f94429901b5f0b1e86 to your computer and use it in GitHub Desktop.
Save grawert/d7ea0041b72b82f94429901b5f0b1e86 to your computer and use it in GitHub Desktop.
RabbitMQ check credentials
#!/usr/bin/env python
import socket
from kombu import Connection
host = "localhost"
port = 5672
user = "username"
password = "secret"
vhost = "/"
url = 'amqp://{0}:{1}@{2}:{3}/{4}'.format(user, password, host, port, vhost)
with Connection(url) as c:
try:
c.connect()
except socket.error:
raise ValueError("Received socket.error, "
"rabbitmq server probably isn't running")
except IOError:
raise ValueError("Received IOError, probably bad credentials")
else:
print "Credentials are valid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment