question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

in Python 3, type(cursor.description[0][0]) is str on Windows but bytes on 64-bit CentOS 7 Linux

See original GitHub issue

On Python 3.5.1:

Windows 7 x64: both pyodbc 3.0.10 and pypyodbc 1.3.3 obtain full column names with the below codes CentOS 7 x86-64 (unixODBC 2.3.1-11.el7): pyodbc 3.0.10 gets full column names, but pypyodbc 1.3.3 gets only the first character — see comments in code below

This occurs with both oracle 12.1 and mysql 5.3 ODBC drivers. For mysql, both ANSI and Unicode drivers.

import pyodbc
import pypyodbc

def get_column_names(conn, table_name):
    with conn.cursor() as cursor:
        cursor = cursor.execute("SELECT * FROM " + table_name)
        column_names = [desc[0] for desc in cursor.description]
    return column_names

oracle_connection_string = "DRIVER=/usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1;..."
table_name = "..."

pyora = pyodbc.connect(oracle_connection_string, autocommit=True)
pypyora = pypyodbc.connect(oracle_connection_string, autocommit=True)

get_column_names(pyora, table_name)
#['BE_ID',
# 'SECURITY_ID',
# 'ID_TYPE',
# 'COUNTRY_OF_REG',
# 'EXCHANGE',
# 'START_DATE',
# 'END_DATE',
# 'INFERRED',
# 'UPDATE_DATE']

get_column_names(pypyora, table_name)
#[b'b', b's', b'i', b'c', b'e', b's', b'e', b'i', b'u']

pyora.close()
pypyora.close()

mysql_connection_string = "Driver=/usr/lib64/libmyodbc5w.so;..."
table_name = "..."

pymys = pyodbc.connect(mysql_connection_string, autocommit=True)
pypymys = pypyodbc.connect(mysql_connection_string, autocommit=True)

get_column_names(pymys, table_name)
#['risk_id',
# 'start_date',
# 'end_date',
# 'last_date',
# 'parent_id',
# 'security_name',
# 'ticker',
# 'cusip',
# 'isin',
# 'sedol',
# 'common_code',
# 'be_id']

get_column_names(pypymys, table_name)
#[b'r', b's', b'e', b'l', b'p', b's', b't', b'c', b'i', b's', b'c', b'b']

pymys.close()
pypymys.close()

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
kaiaeberlicommented, Feb 18, 2016

I am having the same issue with pypyodbc on RHEL 6.5 using unixODBC and freeTDS.

I solved the issue using this link: http://www.pynut.com/?p=241 setting force_unicode = False in the _UpdateDesc() method of pypyodbc.py.

Seems the unicode buffer isnt working.

If I apply this fix, I get back full column names, but all as type bytes. The only remaining problem is decoding this to unicode - a simple b’abc \x80 def’.decode(“cp1252”) doesnt work.

0reactions
nicoleschoencommented, Mar 20, 2017

Looks like this fixes it for python 3, but breaks it for python 2.7 which worked previously.

I now get the exact same issue that was reported for python 3 when I use pypyodbc 1.3.4 with python 2.7 (with 1.3.3 it works fine and column names are returned correctly).

Can the fix be made dependant on the python version, so the latest version of pypyodbc can be used with python 2.7 and python 3?

Read more comments on GitHub >

github_iconTop Results From Across the Web

curses — Terminal handling for character-cell displays ...
Editable text widget for curses supporting Emacs-like bindings. ... Return the user's current erase character as a one-byte bytes object.
Read more >
How do I determine if my python shell is executing in 32bit or ...
I'm having problems building and loading some modules on OS X 10.6. Specifically pysco, which is complaining I'm running in 64bit mode. This...
Read more >
- Teradata Python Module - Community
The Teradata Python Module has been certified to work with Python 3.4+ / 2.7+, Windows/Linux/Mac, 32/64 bit. The easiest way to install the...
Read more >
Considerations in adopting RHEL 8 Red Hat Enterprise Linux 8
Note that all architectures are supported by the standard kernel packages in RHEL 8; no kernel-alt package is needed. Chapter 3. Repositories. Red...
Read more >
CentOS Linux on Hyper-V - A Complete Guide - Altaro
A Walkthrough of CentOS Installation. When you first boot, it will default to Test this media & install CentOS 7. I typically skip...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found