求助:AttributeError: 'str' object has no attribute 'Image_Data'

haojian855 2018-12-21 10:22:05
1、我的环境是python27的
2、代码如下:
# pylint: disable=no-member
import ibm_db
import base64
import io
import os
import sys
import string
from PIL import Image
conn = ibm_db.connect("DATABASE=XXXXdb;HOSTNAME=127.0.0.1;PORT=50000;PROTOCOL=TCPIP;UID=db2admin;PWD=db2admin;", "", "")
if conn:
sql = "SELECT Image_Data,bilno FROM DB2ADMIN.NOTE_MSG where date(sign_date)='2018-10-10' "
stmt = ibm_db.exec_immediate(conn, sql)
result = ibm_db.fetch_both(stmt)
print(result)

for row in result:
print(row)
data = row.Image_Data
bilno = row.bilno
print("saving " + bilno + " ...")
image = Image.open(io.BytesIO(data))
path = "photo\\" + bilno + ".png"
image.save(path)

3、执行代码如下报错:

Traceback (most recent call last):
File "db2connet.py", line 18, in <module>
data = row.Image_Data
AttributeError: 'str' object has no attribute 'Image_Data'

不清楚代码哪点出了问题!!望大神解救一下了!
...全文
1398 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
陈年椰子 2018-12-24
  • 打赏
  • 举报
回复
按你的代码,
image = Image.open(io.BytesIO(data))
里的data 应该是二进制的, 你从数据库里取出的时候, 用 type(data) 看看 , 我怀疑data被转换了, 不是二进制。
haojian855 2018-12-22
  • 打赏
  • 举报
回复
按照你说的,现在已经不报错了!不过又有新问题了!!!
请大神看看呢:
Traceback (most recent call last):
File "db2connet.py", line 25, in <module>
image = Image.open(io.BytesIO(data))
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2657, in open
% (filename if filename else fp))
IOError: cannot identify image file <_io.BytesIO object at 0x02030960>
陈年椰子 2018-12-21
  • 打赏
  • 举报
回复
print(row) 显示的是什么?
按理说 row 应该是个列表
用 data = row[0] 可以得到第一个字段的值。
jQuery Version 1.5 API 中文版 IE用户无法在线查看本文档,请下载jQuery API Version1.5 中文版AIR客户端查看,或者使用chrome,safari,firefox,opera等浏览器查看!!! jQuery 1.5 API Cheat Sheet来源 Selectors Basics #id element .class, .class.class * selector1, selector2 Hierarchy ancestor descendant parent > child prev + next prev ~ siblings Basic Filters :first :last :not(selector) :even :odd :eq(index) :gt(index) :lt(index) :header :animated Content Filters :contains(text) :empty :has(selector) :parent Visibility Filters :hidden :visible Child Filters :nth-child(expr) :first-child :last-child :only-child Attribute Filters [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [attribute|=value] [attribute~=value] [attribute][attribute2] Forms :input :text :password :radio :checkbox :submit :image :reset :button :file Form Filters :enabled :disabled :checked :selected Core jQuery function $.jQuery( selector [, context] ), .jQuery( element ), .jQuery( elementArray ), .jQuery( jQueryObject ), .jQuery( ) $.jQuery( html [, ownerDocument] ), .jQuery( html, props ) $.jQuery( fn ) jQuery Object Accessors $.each( fn(index, element) ) num.size( ) , .length str.selector el.context $.eq( index ) jQuery.error( str ) [el],el.get( [index] ) num.index( ).index( selector ).index( element ) $jQuery.pushStack( elements, [name, arguments] ) arr.toArray( ) Interoperability $jQuery.noConflict( [extreme] ) ver. 04-02-2011 Attributes Attributes str.attr( name ) $.attr( name, val ), .attr( map ), .attr( name, fn(index, attr) ) $.removeAttr( name ) Class $.addClass( class ), .addClass( fn(index, class) ) bool.hasClass( class ) $.removeClass( [class] ), .removeClass( fn(index, class) ) $.toggleClass( class [, switch] ), .toggleClass( fn(index, class) [, switch] ) HTML, text str.html( ) $.html( val ), .html( fn(index, html) ) str.text( ) $.text( val ), .text( fn(index, html) ) Value str,arr.val( ) $.val( val ), .val( fn() ) CSS CSS str.css( name ) $.css( name, val ), .css( map ), .css( name, fn(index, val) ) Positioning obj.offset( ) $.offset( coord ), .offset( fn( index, coord ) ) $.offsetParent( ) obj.position( ) int.scrollTop( ) $.scrollTop( val ) int.scrollLeft( ) $.scrollLeft( val ) Height and Width int.height( ) $.height( val ), .height( fn(index, height ) ) int.width( ) $.width( val ), .width(( fn(index, height ) ) int.innerHeight( ) int.innerWidth( ) int.outerHeight( [margin] ) int.outerWidth( [margin] ) Deferred deferred object = { defdone(doneCallbacks) deffail(failCallbacks) boolisRejected() boolisResolved() defreject([args]) defrejectWith(context, [args]) defresolve([args]) defresolveWith(context, [args]) defthen(doneCallbacks, failCallbacks) }1.5+ def.when(deferreds)1.5+ Traversing Filtering $.eq( index ) $.first( ) $.last( ) $.has( selector ), .has( element ) $.filter( selector ), .filter( fn(index) ) bool.is( selector ) $.map( fn(index, element) ) $.not( selector ), .not( elements ), .not( fn( index ) ) $.slice( start [, end] ) Tree traversal $.children( [selector] ) $.closest( selector [, context] ) arr.closest( selectors [, context] ) $.find( selector ) $.next( [selector] ) $.nextAll( [selector] ) $.nextUntil( [selector] ) $.offsetParent( ) $.parent( [selector] ) $.parents( [selector] ) $.parentsUntil( [selector] ) $.prev( [selector] ) $.prevAll( [selector] ) $.prevUntil( [selector] ) $.siblings( [selector] ) Miscellaneous $.add( selector [, context] ), .add( elements ), .add( html ) $.andSelf( ) $.contents( ) $.end( ) Manipulation Inserting Inside $.append( content ), .append( fn( index, html ) ) $.appendTo( target ) $.prepend( content ), .prepend( fn( index, html ) ) $.prependTo( target ) Inserting Outside $.after( content ), .after( fn() ) $.before( content ), .before( fn() ) $.insertAfter( target ) $.insertBefore( target ) Inserting Around $.unwrap( ) $.wrap( wrappingElement ), .wrap( fn ) $.wrapAll(wrappingElement ), .wrapAll( fn ) $.wrapInner( wrappingElement ), .wrapInner( fn ) Replacing $.replaceWith( content ), .replaceWith( fn ) $.replaceAll( selector ) Removing $.detach( [selector] ) $.empty( ) $.remove( [selector] ) Copying $.clone( [withDataAndEvents], [deepWithDataAndEvents] )1.5∗ Events Page Load $.ready( fn() ) Event Handling $.bind( type [, data ], fn(eventObj) ) $.bind( type [, data], false ) $.bind( array ) $.unbind( [type] [, fn]) $.one( type [, data ], fn(eventObj) ) $.trigger( event [, data]) obj.triggerHandler( event [, data]) $.delegate( selector, type, [data], handler) $.undelegate( [selector, type, [handler]]) Live Events $.live( eventType [, data], fn() ) $.die( ), .die( [eventType] [, fn() ]) Interaction Helpers $.hover( fnIn(eventObj), fnOut(eventObj)) $.toggle( fn(eventObj), fn2(eventObj) [, ...]) Event Helpers function ( [data,] [fn] ) $.blur,.mousedown,.change,.mouseenter,.click,.mouseleave,.dblclick,.mousemove,.error,.mouseout,.focus,.mouseover,.focusin,.mouseup,.focusout,.resize,.keydown,.scroll,.keypress,.select,.keyup,.submit,.load( [data,] fn ),.unload( [data,] fn ) Event object event = { elcurrentTarget, *data, boolisDefaultPrevented(), boolisImmediatePropagationStopped(), boolisPropagationStopped(), strnamespace, numpageX, numpageY, preventDefault(), elrelatedTarget, objresult, stopImmediatePropagation(), stopPropagation(), eltarget, numtimeStamp, strtype, strwhich } Effects Basics $.show( [ duration [, easing] [, fn] ] ) $.hide( [ duration [, easing] [, fn] ] ) $.toggle( [showOrHide] ) $.toggle( duration [, easing] [, fn] ) Sliding $.slideDown( duration [, easing] [, fn] ) $.slideUp( duration [, easing] [, fn] ) $.slideToggle( [duration] [, easing] [, fn] ) Fading $.fadeIn( duration [, easing] [, fn] ) $.fadeOut( duration [, easing] [, fn] ) $.fadeTo( [duration,] opacity [, easing] [, fn] ) $.fadeToggle( [duration,] [, easing] [, fn] ) Custom $.animate( params [, duration] [, easing] [, fn] ) $.animate( params, options ) $.stop( [clearQueue] [, jumpToEnd] ) $.delay( duration [, queueName] ) Settings booljQuery.fx.off numjQuery.fx.interval AJAX Low-Level Interface jqXHRjQuery.ajax( options, [settings] )1.5+ mapaccepts boolasync = true fnbeforeSend( jqXHR, config) boolcache = true fncomplete( jqXHR, status) mapcontents strcontentType objcontext mapconverters boolcrossDomain obj, strdata fndataFilter( data, type ) boolglobal = true mapheaders boolifModified = false strjsonp fnjsonpCallback strpassword boolprocessData = true strscriptCharset mapstatusCode numtimeout booltraditional strtype = 'GET' strurl = curr. page strusername fnxhr strdataType ∈ {xml, json, script, html} fnerror( jqXHR, status, errorThrown ) fnsuccess( data, status, jqXHR ) jQuery.ajaxSetup( options ) Shorthand Methods $.load( url [, data] [, fn( responseText, status, XHR )] ) jqXHRjQuery.get( url [, data] [, fn( data, status, XHR )] [, type] ) jqXHRjQuery.getJSON( url [, data] [, fn( data, status )] ) jqXHRjQuery.getScript( url [, fn( data, status )] ) jqXHRjQuery.post( url [, data] [, fn( data, status )] [, type] ) Global Ajax Event Handlers $.ajaxComplete( fn( event, XHR, options ) ) $.ajaxError( fn( event, XHR, options, thrownError ) ) $.ajaxSend( fn( event, XHR, options ) ) $.ajaxStart( fn( ) ) $.ajaxStop( fn( ) ) $.ajaxSuccess( fn(event, XHR, options) ) Miscellaneous str.serialize( ) [obj].serializeArray( ) strjQuery.param( obj, [traditional] ) Utilities Browser and Feature Detection objjQuery.support objjQuery.browserdeprecated strjQuery.browser.versiondeprecated booljQuery.boxModeldeprecated Basic operations objjQuery.each( obj, fn( index, valueOfElement ) ) objjQuery.extend( [deep,] target, obj1 [, objN] ) arrjQuery.grep( array, fn( element, index ) [, invert] ) arrjQuery.makeArray( obj ) arrjQuery.map( array, fn( element, index ) ) numjQuery.inArray( val, array ) arrjQuery.merge( first, second ) fnjQuery.noop fnjQuery.proxy( fn, scope ), jQuery.proxy( scope, name ) fnjQuery.sub( )1.5+ arrjQuery.unique( array ) strjQuery.trim( str ) objjQuery.parseJSON( str ) Data functions $.clearQueue( [name] ) $.dequeue( [name] ), jQuery.dequeue( [name] ) objjQuery.data( element, key ), jQuery.data( ) obj.data( ), .data( key ) $.data( key, val ), .data( obj ) $.removeData( [name] ) [fn].queue( [name] ) jQuery.queue( [name] ) $.queue( [name,] fn( next ) ), jQuery.queue( [name,] fn( ) ) $.queue( [name,] queue ), jQuery.queue( [name,] queue ) Test operations strjQuery.type( obj ) booljQuery.isArray( obj ) booljQuery.isEmptyObject( obj ) booljQuery.isFunction( obj ) booljQuery.isPlainObject( obj ) booljQuery.isWindow( obj ) 获取jQuery 1.5 API文档
核心 jQuery 核心函数 jQuery(expr, [context]) jQuery(html, [ownerDoc]) jQuery(elements) jQuery(callback) jQuery 对象访问 each(callback) size() length selector context get() get(index) index(subject) 数据缓存 data(name , [value]) removeData(name) queue(name ,[cb|queue]) dequeue(name) 插件机制 jQuery.fn.extend(object) jQuery.extend(object) 多库共存 jQuery.noConflict([extreme]) 属性 属性 attr(name) attr(properties) attr(key, value) attr(key, fn) removeAttr(name) CSS 类 addClass(class) removeClass([class]) toggleClass(class [, switch]) HTML代码 html( [val] ) 文本 text( [val] ) 值 val( [val] ) CSS CSS css(name) css(properties) css(name, value) 位置 offset() position() scrollTop( [val] ) scrollLeft( [val] ) 尺寸 height( [val] ) width( [val] ) innerHeight() innerWidth() outerHeight(options) outerWidth(options) 选择器 基本 #id element .class * selector1,selector2,selectorN 层级 ancestor descendant parent > child prev + next prev ~ siblings 基本 :first :last :not :even :odd :eq :gt :lt :header :animated 内容 :contains :empty :has :parent 可见性 :hidden :visible 属性 [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [attrSel1][attrSel2][attrSelN] 子元素 :nth-child :first-child :last-child :only-child 表单 :input :text :password :radio :checkbox :submit :image :reset :button :file :hidden 表单对象属性 :enabled :disabled :checked :selected 文档处理 内部插入 append(content) appendTo(content) prepend(content) prependTo(content) 外部插入 after(content) before(content) insertAfter(content) insertBefore(content) 包裹 wrap(html) wrap(elem) wrapAll(html) wrapAll(elem) wrapInner(html) wrapInner(elem) 替换 replaceWith(content) replaceAll(selector) 删除 empty() remove([expr]) 复制 clone() clone(true) 筛选 过滤 eq(index) hasClass(class) filter(expr) filter(fn) is(expr) map(callback) not(expr) slice(start, [end]) 查找 add(expr) children([expr]) closest([expr]) contents() find(expr) next([expr]) nextAll([expr]) offsetParent() parent([expr]) parents([expr]) prev([expr]) prevAll([expr]) siblings([expr]) 串联 andSelf() end() 事件 页面载入 ready(fn) 事件处理 bind(type, [data], fn) one(type, [data], fn) trigger(type, [data]) triggerHandler(type, [data]) unbind([type], [data]) 事件委派 live(type, fn) die([type], [fn]) 事件切换 hover(over, out) toggle(fn, fn2, [fn3, fn4, ...]) 事件 blur( [fn] ) change( [fn] ) click( [fn] ) dblclick( [fn] ) error( [fn] ) focus( [fn] ) keydown( [fn] ) keypress( [fn] ) keyup( [fn] ) mousedown(fn) mousemove(fn) mouseout(fn) mouseover(fn) mouseup(fn) resize(fn) scroll(fn) select( [fn] ) submit( [fn] ) unload(fn) 效果 基本 show() show(speed, [callback]) hide() hide(speed, [callback]) toggle() toggle(switch) toggle(speed, [callback]) 滑动 slideDown(speed, [callback]) slideUp(speed, [callback]) slideToggle(speed, [callback]) 淡入淡出 fadeIn(speed, [callback]) fadeOut(speed, [callback]) fadeTo(speed, opacity, [fn]) 自定义 animate(param,[dur],[e],[fn]) animate(params, options) stop([clearQueue], [gotoEnd]) 设置 jQuery.fx.off Ajax Ajax 请求 $.ajax([options]) load(url, [data], [callback]) $.get(url, [data], [fn], [type]) $.getJSON(url, [data], [fn]) $.getScript(url, [callback]) $.post(url, [data], [fn], [type]) Ajax 事件 ajaxComplete(callback) ajaxError(callback) ajaxSend(callback) ajaxStart(callback) ajaxStop(callback) ajaxSuccess(callback) 其它 $.ajaxSetup([options]) serialize() serializeArray() 工具 浏览器及特性检测 $.support $.browser $.browser.version $.boxModel 数组和对象操作 $.each(object, [callback]) $.extend([d],tgt,obj1,[objN]) $.grep(array, fn, [invert]) $.makeArray(obj) $.map(array, callback) $.inArray(value, array) $.merge(first, second) $.unique(array) 测试操作 $.isArray(obj) $.isFunction(obj) 字符串操作 $.trim(str) URL $.param(obj) 关于 关于jQuery 1.3 版翻译 关于jQuery 1.2 版翻译 提交bug及获取更新
核心 jQuery 核心函数 jQuery(expr, [context]) jQuery(html, [ownerDoc]) jQuery(elements) jQuery(callback) jQuery 对象访问 each(callback) size() length selector context get() get(index) index(subject) 数据缓存 data(name , [value]) removeData(name) queue(name ,[cb|queue]) dequeue(name) 插件机制 jQuery.fn.extend(object) jQuery.extend(object) 多库共存 jQuery.noConflict([extreme]) 属性 属性 attr(name) attr(properties) attr(key, value) attr(key, fn) removeAttr(name) CSS 类 addClass(class) removeClass([class]) toggleClass(class [, switch]) HTML代码 html( [val] ) 文本 text( [val] ) 值 val( [val] ) CSS CSS css(name) css(properties) css(name, value) 位置 offset() position() scrollTop( [val] ) scrollLeft( [val] ) 尺寸 height( [val] ) width( [val] ) innerHeight() innerWidth() outerHeight(options) outerWidth(options) 选择器 基本 #id element .class * selector1,selector2,selectorN 层级 ancestor descendant parent > child prev + next prev ~ siblings 基本 :first :last :not :even :odd :eq :gt :lt :header :animated 内容 :contains :empty :has :parent 可见性 :hidden :visible 属性 [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [attrSel1][attrSel2][attrSelN] 子元素 :nth-child :first-child :last-child :only-child 表单 :input :text :password :radio :checkbox :submit :image :reset :button :file :hidden 表单对象属性 :enabled :disabled :checked :selected 文档处理 内部插入 append(content) appendTo(content) prepend(content) prependTo(content) 外部插入 after(content) before(content) insertAfter(content) insertBefore(content) 包裹 wrap(html) wrap(elem) wrapAll(html) wrapAll(elem) wrapInner(html) wrapInner(elem) 替换 replaceWith(content) replaceAll(selector) 删除 empty() remove([expr]) 复制 clone() clone(true) 筛选 过滤 eq(index) hasClass(class) filter(expr) filter(fn) is(expr) map(callback) not(expr) slice(start, [end]) 查找 add(expr) children([expr]) closest([expr]) contents() find(expr) next([expr]) nextAll([expr]) offsetParent() parent([expr]) parents([expr]) prev([expr]) prevAll([expr]) siblings([expr]) 串联 andSelf() end() 事件 页面载入 ready(fn) 事件处理 bind(type, [data], fn) one(type, [data], fn) trigger(type, [data]) triggerHandler(type, [data]) unbind([type], [data]) 事件委派 live(type, fn) die([type], [fn]) 事件切换 hover(over, out) toggle(fn, fn2, [fn3, fn4, ...]) 事件 blur( [fn] ) change( [fn] ) click( [fn] ) dblclick( [fn] ) error( [fn] ) focus( [fn] ) keydown( [fn] ) keypress( [fn] ) keyup( [fn] ) mousedown(fn) mousemove(fn) mouseout(fn) mouseover(fn) mouseup(fn) resize(fn) scroll(fn) select( [fn] ) submit( [fn] ) unload(fn) 效果 基本 show() show(speed, [callback]) hide() hide(speed, [callback]) toggle() toggle(switch) toggle(speed, [callback]) 滑动 slideDown(speed, [callback]) slideUp(speed, [callback]) slideToggle(speed, [callback]) 淡入淡出 fadeIn(speed, [callback]) fadeOut(speed, [callback]) fadeTo(speed, opacity, [fn]) 自定义 animate(param,[dur],[e],[fn]) animate(params, options) stop([clearQueue], [gotoEnd]) 设置 jQuery.fx.off Ajax Ajax 请求 $.ajax([options]) load(url, [data], [callback]) $.get(url, [data], [fn], [type]) $.getJSON(url, [data], [fn]) $.getScript(url, [callback]) $.post(url, [data], [fn], [type]) Ajax 事件 ajaxComplete(callback) ajaxError(callback) ajaxSend(callback) ajaxStart(callback) ajaxStop(callback) ajaxSuccess(callback) 其它 $.ajaxSetup([options]) serialize() serializeArray() 工具 浏览器及特性检测 $.support $.browser $.browser.version $.boxModel 数组和对象操作 $.each(object, [callback]) $.extend([d],tgt,obj1,[objN]) $.grep(array, fn, [invert]) $.makeArray(obj) $.map(array, callback) $.inArray(value, array) $.merge(first, second) $.unique(array) 测试操作 $.isArray(obj) $.isFunction(obj) 字符串操作 $.trim(str) URL $.param(obj) 关于 关于jQuery 1.3 版翻译 关于jQuery 1.2 版翻译 提交bug及获取更新

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧