# Problems with ODBC driver and pyodbc when query returns error

**URL:** https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551
**Category:** Uncategorized
**Created:** [December 12, 2017, 7:15pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551 "2017-12-12T19:15:30Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![juanchoverd](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@juanchoverd](https://community.dremio.com/u/juanchoverd)
#### Post date: [December 12, 2017, 7:15pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/1 "2017-12-12T19:15:30Z")

</div>

I’m trying the ODBC driver with pyodbc and I’ve found out that whenever the query I run is invalid for whatever reason (wrong table name, invalid query format, etc) I get a segmentation fault.  
I’m guessing that the driver isn’t able to handle errors returned by Dremio. Valid queries run fine and return values.

I’ve tried this on Mac OS and in an Ubuntu docker container.

Example queries:  
“select now()” -\> runs fine  
"select nowasdf()" -\> segmentation fault  
"select \* from existing\_source.existing\_table" -\> runs fine  
"select \* from existing\_source.not\_existing\_table" -\> segmentation fault  
"invalid query" -\> segmentation fault

Code:

import pyodbc

host = 'myhost  
port = 31010  
user = 'myuser’  
password = ‘mypass’

connection = pyodbc.connect(“Driver={Dremio Connector};ConnectionType=Direct;HOST={%s};PORT={%d};AuthenticationType=Plain;UID={%s};PWD={%s}”  
% (host, port, user, password),autocommit=True)

cursor = connection.cursor()

try:  
cursor.execute(‘invalid query’)  
data = cursor.fetchall()  
print data  
except Exception as e:  
print e.message  
finally:  
cursor.close()  
connection.close()

---

<div class="post-metadata">

### Author: ![can](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/can/32/40_2.png) [@can](https://community.dremio.com/u/can)
#### Post date: [December 12, 2017, 8:22pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/2 "2017-12-12T20:22:38Z")

</div>

hey @juanchoverd we’re taking a look – thanks for the detailed steps. Can you share the version of the ODBC driver you are using?

---

<div class="post-metadata">

### Author: ![juanchoverd](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@juanchoverd](https://community.dremio.com/u/juanchoverd)
#### Post date: [December 12, 2017, 8:49pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/3 "2017-12-12T20:49:14Z")

</div>

I’m using the rpm from [dremio.com/download](http://dremio.com/download) dremio-odbc-1.3.14.1043-1.x86\_64

---

<div class="post-metadata">

### Author: ![can](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/can/32/40_2.png) [@can](https://community.dremio.com/u/can)
#### Post date: [December 12, 2017, 9:41pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/4 "2017-12-12T21:41:40Z")

</div>

@juanchoverd couple of questions to narrow down the issue:

- If possible, could you see if issuing similar queries from a non-python based tools result in the same issue.
- Could set driver logging to level 6 and share the driver logs. You can do this by modifying `dremio.drillodbc.ini` under `/opt/dremio-odbc/lib64/`
- Could you share versions of Python, PYODBC, unixODBC/iODBC?

---

<div class="post-metadata">

### Author: ![juanchoverd](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@juanchoverd](https://community.dremio.com/u/juanchoverd)
#### Post date: [December 13, 2017, 2:04pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/5 "2017-12-13T14:04:10Z")

</div>

Python 2.7.12  
pyodbc==4.0.21  
unixODBC 2.3.1

I’ve tried using isql and all of the invalid queries return “[ISQL]ERROR: Could not SQLPrepare”. This is with the verbose flag. I’m not sure if that is how it is supposed to work of if it supposed to return more detailed errors like “Table not found”. Valid queries run fine.

I’ve attached the logs created after running the python script.

[logs.zip](https://us1.discourse-cdn.com/flex020/uploads/dremio/original/1X/99a01d6f5b356919a798ad4285f8d3c4abf1cf74.zip) (8.0 KB)

---

<div class="post-metadata">

### Author: ![can](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/can/32/40_2.png) [@can](https://community.dremio.com/u/can)
#### Post date: [December 13, 2017, 6:48pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/6 "2017-12-13T18:48:01Z")

</div>

Thanks for the info @juanchoverd. We’ll reach out once we know more on the cause.

---

<div class="post-metadata">

### Author: ![laurent](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/laurent/32/16_2.png) [@laurent](https://community.dremio.com/u/laurent)
#### Post date: [December 14, 2017, 4:23pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/7 "2017-12-14T16:23:47Z")

</div>

We haven’t fully identified the root cause, but it seems specific to pyodbc 4.0. If you have the opportunity, can you give pyodbc 3.x a chance? in our testing with it, error handling looked fine.

---

<div class="post-metadata">

### Author: ![juanchoverd](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@juanchoverd](https://community.dremio.com/u/juanchoverd)
#### Post date: [December 14, 2017, 7:28pm UTC](https://community.dremio.com/t/problems-with-odbc-driver-and-pyodbc-when-query-returns-error/551/8 "2017-12-14T19:28:11Z")

</div>

Laurent thank you for your help. I’ve tried pyodbc 3.1.1 and it works correctly in my Macbook but it still does not work on the Ubuntu container. It still throws a segmentation fault. I have also tried pyodbc 2.1.11 in the Ubuntu container and it doesn’t work either.
