Created
December 18, 2017 20:23
-
-
Save utkjad/0e0fc591bc283cd8d5b1cb7806541c8b to your computer and use it in GitHub Desktop.
Utility function to connect to Pyhive on HTTP mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyhive import hive | |
def connect_to_pyhive(): | |
""" Connects to Pyhive with HTTP mode | |
""" | |
conn = hive.connect(thrift_transport=add_http_mode_support()) | |
cursor = conn.cursor() | |
cursor.execute("show databases") | |
print cursor.fetchone() | |
def add_http_mode_support(username="xxx", password="xxx", port=10001, httpPath="/cliservice", host="127.0.0.1", transportMode="http"): | |
""" Utility function which geenrate Transport client object which in turn can be passwd to hive connection to | |
establish the HTTP mode connection. | |
""" | |
ap = "%s:%s" % (username, password) | |
import base64 | |
from thrift.transport.THttpClient import THttpClient | |
_transport = THttpClient(host, port=port, path=httpPath) | |
_transport.setCustomHeaders({"Authorization": "Basic "+base64.b64encode(ap).strip()}) | |
return _transport | |
if __name__ == '__main__': | |
connect_to_pyhive() |
why username and password is base64encode?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
were you able to connect to the hive server which transport mode configured as "http"?