<?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: inserting and retrieving python dataframe in hana database in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257868#M4590852</link>
    <description>&lt;P&gt;Hi Harsh,&lt;/P&gt;&lt;P&gt;you can also pass the encrypt parameter via the connection string, that is the parameter of create_engine. You can check the &lt;A href="https://github.com/mkemeter/public/blob/master/Melbourne%20Housing.ipynb"&gt;Jupyter notebook&lt;/A&gt; from &lt;A href="https://blogs.sap.com/2020/06/24/on-machine-learning-without-location-data/"&gt;this blog&lt;/A&gt; for an example.&lt;BR /&gt;&lt;BR /&gt;The relevant part:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;connection_string = 'hana://%s:%s@%s:%s/?encrypt=true&amp;amp;sslvalidatecertificate=false' % (hdb_user, hdb_password, hdb_host, hdb_port)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;BR /&gt;Mathias&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jul 2020 08:44:03 GMT</pubDate>
    <dc:creator>mkemeter</dc:creator>
    <dc:date>2020-07-03T08:44:03Z</dc:date>
    <item>
      <title>inserting and retrieving python dataframe in hana database</title>
      <link>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaq-p/12257866</link>
      <description>&lt;P&gt;&lt;BR /&gt;I have a python dataframe that I want to insert directly into HANA database and also wants to read it from database.&lt;/P&gt;
  &lt;P&gt;I have tried this code :&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;from sqlalchemy import create_engine
engine = create_engine('hana+pyhdb://username:password@example.com:port')
my_df = pd.DataFrame([[1,2],[3,4],[5,6],[7,8]], columns=["A","B"])
my_df.to_sql('table_name', con = engine, index =False, if_exists ='replace')&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;STRONG&gt;Error: DBAPIError: (hdbcli.dbapi.Error) (4321, 'only secure connections are allowed') (Background on this error at:&lt;A href="http://sqlalche.me/e/dbapi"&gt;http://sqlalche.me/e/dbapi&lt;/A&gt;)&lt;/STRONG&gt;*&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Is this about adding ssl certificate? How to add it in the engine ?&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;However, I'm able to connect OK via the Python API using the encrypt option:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;conn = dbapi.connect(
    address="host",
    port=portnr,
    encrypt="true",
    user="user",
    password="pwd")&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;But, if I pass this connection object here:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;my_df.to_sql('table_name', con = conn, index =False, if_exists ='replace')&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I'll still get an error. How to fix this?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 06:12:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaq-p/12257866</guid>
      <dc:creator>hrshjrwl</dc:creator>
      <dc:date>2020-07-03T06:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: inserting and retrieving python dataframe in hana database</title>
      <link>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257867#M4590851</link>
      <description>&lt;P&gt;Hi Harsh,&lt;/P&gt;&lt;P&gt;Does this concern the SAP Cloud Platform, SAP HANA Service? &lt;/P&gt;&lt;P&gt;I have posted a blog with tutorial videos how to set this up&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://blogs.sap.com/2019/01/17/secure-client-connections-for-the-sap-hana-service-by-the-sap-hana-academy/" target="test_blank"&gt;https://blogs.sap.com/2019/01/17/secure-client-connections-for-the-sap-hana-service-by-the-sap-hana-academy/&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For the SAP HANA Cloud service or on-premises, e.g. SAP HANA, express edition secure connections by default is not enforced. Are you the system administrator of the SAP HANA system as well? &lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 07:05:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257867#M4590851</guid>
      <dc:creator>dvankempen</dc:creator>
      <dc:date>2020-07-03T07:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: inserting and retrieving python dataframe in hana database</title>
      <link>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257868#M4590852</link>
      <description>&lt;P&gt;Hi Harsh,&lt;/P&gt;&lt;P&gt;you can also pass the encrypt parameter via the connection string, that is the parameter of create_engine. You can check the &lt;A href="https://github.com/mkemeter/public/blob/master/Melbourne%20Housing.ipynb"&gt;Jupyter notebook&lt;/A&gt; from &lt;A href="https://blogs.sap.com/2020/06/24/on-machine-learning-without-location-data/"&gt;this blog&lt;/A&gt; for an example.&lt;BR /&gt;&lt;BR /&gt;The relevant part:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;connection_string = 'hana://%s:%s@%s:%s/?encrypt=true&amp;amp;sslvalidatecertificate=false' % (hdb_user, hdb_password, hdb_host, hdb_port)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;BR /&gt;Mathias&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 08:44:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257868#M4590852</guid>
      <dc:creator>mkemeter</dc:creator>
      <dc:date>2020-07-03T08:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: inserting and retrieving python dataframe in hana database</title>
      <link>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257869#M4590853</link>
      <description>&lt;P&gt;Hi Harsh, &lt;/P&gt;&lt;P&gt;We also have another method with SAP developed python API in HANA_ML, specifically with the connection context object. After installing &lt;A href="https://pypi.org/project/hana-ml/"&gt;HANA_ML&lt;/A&gt;, you can set up a connection such as the following example. You will notice like the examples above, you need to provide encrypt and sslvalidatecertificate. This is probably what caused you original problem.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from hana_ml.dataframe import ConnectionContext
with open(os.path.join(os.getcwd(), 'env_cloud.json')) as f: 
    hana_env = json.load(f)
    port = hana_env['port'] 
    user = hana_env['user'] 
    url = hana_env['url']
    pwd = hana_env['pwd']

cc = ConnectionContext(url, port, user, pwd, autocommit=True, encrypt='true', sslValidateCertificate='false')
cur = cc.connection.cursor()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jul 2020 12:14:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257869#M4590853</guid>
      <dc:creator>LynnS1</dc:creator>
      <dc:date>2020-07-03T12:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: inserting and retrieving python dataframe in hana database</title>
      <link>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257870#M4590854</link>
      <description>&lt;P&gt;Thank you, it solved my problem.&lt;/P&gt;</description>
      <pubDate>Sat, 07 May 2022 15:54:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/inserting-and-retrieving-python-dataframe-in-hana-database/qaa-p/12257870#M4590854</guid>
      <dc:creator>former_member802800</dc:creator>
      <dc:date>2022-05-07T15:54:59Z</dc:date>
    </item>
  </channel>
</rss>

