Pyodbc.row object to actual value from database

720 Views Asked by At

I am trying to pull data out of an IBM i-Series server (previously AS400) using pyobdc. I am using OBDC Data Source Administrator and iSeries Access ODBC Driver. Here is the code:

import pyodbc
conn = pyodbc.connect('DRIVER={iSeries Access ODBC Driver};system=SERVER;UID=USER;PWD=PASS;unicode_results=True')
conn.setencoding('utf-8')
c1=conn.cursor()
c1.execute("""select TEST from TESTER.ITEMTEST where TEST='005911'""")
<pyodbc.Cursor object at 0x02A1F460>
rows = c1.fetchall()
print(rows[0])

This is what is returned:

(b'\xf0\xf0\xf5\xf9\xf1\xf1@@@@@@@@@', )

From what I've read, this is a pyodbc.Row object. I've searched the internet high and low and cannot find anything that solves my problem.

One of our systems developers in house said maybe there is some sort of setting in the OBDC Administrator that I need to change, but everything seems to be setup properly.

Here are some screenshots of the OBDC Administrator and how I have the driver setup:

Screens

Is there a way to convert the pyodbc.Row object to the actual value contained within the database? Or is there something else I am missing?

I have tried:

rows[0].TEST

and it still returns a pyodbc.Row object. All I would like to do is return the actual value retrieved from the server and not a pyodbc.Row object.

When I use:

c1.description

I get:

(('TEST', <class 'bytearray'>, None, 15, 15, 0, False),)

The actual value I should get is: 005911

1

There are 1 best solutions below

0
On

I changed the connection line and it fixed everything. All I had to add was: TRANSLATE=1

conn = pyodbc.connect('DRIVER={iSeries Access ODBC Driver};system=SERVER;TRANSLATE=1;UID=USER;PWD=PASS')