<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Not able to connect to hiveserver2  to access hivetables with python in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Not-able-to-connect-to-hiveserver2-to-access-hivetables-with/m-p/277226#M207496</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/69219"&gt;@ranger&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try something like this it&amp;nbsp;&lt;SPAN&gt;explains how to&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;connect Hive running on a remote host&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp; (&lt;/SPAN&gt;&lt;STRONG&gt;HiveSever2&lt;/STRONG&gt;&lt;SPAN&gt;)&amp;nbsp; using commonly used Python package, Pyhive?&amp;nbsp;There are a lot of other Python packages available to connect to remote Hive, but Pyhive package is one of the easy and well-maintained and supported package&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here I am assuming you installed already the Pyhive package if not please do that first!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;from phive import hive&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;import re,os, time&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;host_name = "localhost"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;port = 10001&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;user = "hive"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;password ="hive"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;database = "employeeDB"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;def hiveconnection(host_name, port, user,password, database):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; conn = hive.Connection(host=host_name, port=port, username=user, password=password,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; database=database, auth='CUSTOM')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cur = conn.cursor()&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cur.execute('select * from employees returns limit 5')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result = cur.fetchall()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return result&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;# Call above function&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;output = hiveconnection(host_name, port, user,password, database)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;print(output)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before you attempt to connect using Pyhive you should execute the below steps to install the Pyhive package below are the step on an ubuntu machine as Pyhive is dependent on these Modules:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Installing gcc&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;sudo apt-get install gcc&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Install Thrif&lt;/STRONG&gt;t&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;pip install thrift+&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Install SASL&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;pip install sasl&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Install thrift sasl&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;pip install thrift_sasl&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After the above steps have run successfully, you can go ahead and install Pyhive using pip:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;pip install pyhive&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;should you encounter Pyhive sasl fatal error install the below dependencies.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;sudo apt-get install libsasl2-dev&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now you can re-test your hive database connection&lt;/P&gt;&lt;P&gt;Please let me know&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Sep 2019 12:37:30 GMT</pubDate>
    <dc:creator>Shelton</dc:creator>
    <dc:date>2019-09-14T12:37:30Z</dc:date>
  </channel>
</rss>

