找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 144|回复: 0

[求助] python调用ibm_db连接库报错UnicodeDecodeError: 'ascii'

0

主题

0

帖子

0

积分

贫民

积分
0
wx_M3X0HCWH 发表于 2020-5-10 19:02:50 | 显示全部楼层 |阅读模式
本帖最后由 wx_M3X0HCWH 于 2020-5-10 19:26 编辑

win下调用DB2库,报错,代码如下:
  1. # -*- coding: utf-8 -*-
  2. import ibm_db
  3. import sys
  4. import imp
  5. imp.reload(sys)


  6. class myDB2():
  7.     try:
  8.         conn_str = 'DATABASE=TEST;HOSTNAME=192.168.43.52;PORT=50000;PROTOCOL=TCPIP;UID=user;PWD=user;'
  9.         conn = ibm_db.connect(conn_str, '', '')
  10.     except:
  11.         print("no connection:", ibm_db.conn_errormsg())
  12.     else:
  13.         print("The connection was successful")

  14.     sql = "select * from subsys_pvt_cfg"
  15.     stmt = ibm_db.exec_immediate(conn, sql)
  16.     result = ibm_db.fetch_tuple(stmt)
  17.     while result:
  18.         #print(result[0], result[1])
  19.         result = ibm_db.fetch_tuple(stmt)


  20. # --------------------------------------------------
  21. if __name__ == '__main__':  # 如果整个程序是主程序
  22.     myDB2()
复制代码

----------------------------------------------------------------------------------
报错如下:
PS E:\my_program\python\vscode> & "D:/Program Files/python/python.exe" e:/my_program/python/vscode/pyqtTest/db2test.py
Traceback (most recent call last):
  File "e:/my_program/python/vscode/pyqtTest/db2test.py", line 12, in myDB2
Exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "e:/my_program/python/vscode/pyqtTest/db2test.py", line 9, in <module>
  File "e:/my_program/python/vscode/pyqtTest/db2test.py", line 14, in myDB2
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbc in position 29: ordinal not in range(128)


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表