title: How to pass along username and password to cassandra in python
body: <p>I'm learning and just setup my cassandra cluster and trying to use python as the client to interact with it. In the yaml, I set the authenticator to be PasswordAuthenticator.</p>
  <p>So now I plan to provide my username and password over to the connect function but find no where to put them.</p>
  <pre class="lang-py prettyprint-override"><code>cluster = Cluster(hosts)
  session = cluster.connect(keyspace)
  </code></pre>
  <p>Basically, you provide only the host and the keyspace. The documentation kind of suggest a connection with anonymous?
  <a href="http://datastax.github.io/python-driver/getting_started.html#connecting-to-cassandra" rel="nofollow noreferrer">http://datastax.github.io/python-driver/getting_started.html#connecting-to-cassandra</a></p>
  <p>If I just use the example, I will get the following error</p>
  <pre><code>raise NoHostAvailable(&quot;Unable to connect to any servers&quot;, errors)
  cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'hou722067': AuthenticationFailed('Remote end requires authentication.',)})
  </code></pre>
  <p>Is the authentication information supplied through some config files? It seems like a very basic functionality and I can't imagine it's not covered in the python client driver. I must have miss something.</p>
  <p>In short, my question is: How do I login to cassandra using python?</p>
  <p>Thanks in advance for any hint possible!</p>
  <p>=================================================
  Got it figured.</p>
  <p>I should provide the username and password in the auth_provider field which is a function returning a dictionary containing ‘username’ and ‘password’ keys with appropriate string values.</p>
  <p>Something like</p>
  <pre class="lang-py prettyprint-override"><code>def getCredential(self, host):
      credential = {'username':'myUser', 'password':'myPassword'}
                      return credential
      
  cluster = Cluster(nodes, auth_provider=getCredential)
  </code></pre>