在尝试提取exif数据时,我不明白为什么我会收到索引错误

时间:2015-12-23 07:46:43

标签: python-2.7 gps exif

来自图像的样本数据的代码和错误:

*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ce2aff5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010c22cdeb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ce3361d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010cd80a9a ___forwarding___ + 970
    4   CoreFoundation                      0x000000010cd80648 _CF_forwarding_prep_0 + 120
    5   App                           0x000000010af420f1 -[IMAJavascriptBridge handleMessageInitialized:] + 157
    6   CoreFoundation                      0x000000010cdf782c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    7   CoreFoundation                      0x000000010cdf756b _CFXRegistrationPost + 427
    8   CoreFoundation                      0x000000010cdf72d2 ___CFXNotificationPost_block_invoke + 50
    9   CoreFoundation                      0x000000010ce3cb02 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1986
    10  CoreFoundation                      0x000000010ccf2409 _CFXNotificationPost + 633
    11  Foundation                          0x000000010bdba259 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    12  App                           0x000000010af43c72 -[IMAJavascriptSession didReceiveMessage:] + 304
    13  App                           0x000000010af43008 -[IMAJavascriptDispatcher processNewMessage:] + 310
    14  App                           0x000000010af42bcb -[IMAJavascriptDispatcher processNewMessageWithChannelName:data:] + 144
    15  App                           0x000000010af42633 -[IMAJavascriptBridge webView:didReceiveMessage:] + 165
    16  App                           0x000000010af5a8f9 -[IMAWKWebView userContentController:didReceiveScriptMessage:] + 164
    17  WebKit                              0x000000010f311ced _ZN28ScriptMessageHandlerDelegate14didPostMessageERN6WebKit12WebPageProxyERNS0_13WebFrameProxyERKNS0_18SecurityOriginDataERN7WebCore21SerializedScriptValueE + 217
    18  WebKit                              0x000000010f2c2b73 _ZN6WebKit29WebUserContentControllerProxy14didPostMessageERN3IPC10ConnectionEyyRKNS_18SecurityOriginDataEyRKNS1_13DataReferenceE + 221
    19  WebKit                              0x000000010f2c4868 _ZN3IPC13handleMessageIN8Messages29WebUserContentControllerProxy14DidPostMessageEN6WebKit29WebUserContentControllerProxyEMS5_FvRNS_10ConnectionEyyRKNS4_18SecurityOriginDataEyRKNS_13DataReferenceEEEEvS7_RNS_14MessageDecoderEPT0_T1_ + 142
    20  WebKit                              0x000000010f1239e5 _ZN3IPC18MessageReceiverMap15dispatchMessageERNS_10ConnectionERNS_14MessageDecoderE + 113
    21  WebKit                              0x000000010f2a6210 _ZN6WebKit15WebProcessProxy17didReceiveMessageERN3IPC10ConnectionERNS1_14MessageDecoderE + 24
    22  WebKit                              0x000000010f0e191a _ZN3IPC10Connection15dispatchMessageENSt3__110unique_ptrINS_14MessageDecoderENS1_14default_deleteIS3_EEEE + 102
    23  WebKit                              0x000000010f0e3be2 _ZN3IPC10Connection18dispatchOneMessageEv + 114
    24  JavaScriptCore                      0x000000010bab0ad5 _ZN3WTF7RunLoop11performWorkEv + 437
    25  JavaScriptCore                      0x000000010bab11b2 _ZN3WTF7RunLoop11performWorkEPv + 34
    26  CoreFoundation                      0x000000010cd56bc1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    27  CoreFoundation                      0x000000010cd4caec __CFRunLoopDoSources0 + 556
    28  CoreFoundation                      0x000000010cd4bfa3 __CFRunLoopRun + 867
    29  CoreFoundation                      0x000000010cd4b9b8 CFRunLoopRunSpecific + 488
    30  GraphicsServices                    0x0000000110bcdad2 GSEventRunModal + 161
    31  UIKit                               0x000000010db9c8fc UIApplicationMain + 171
    32  App                           0x000000010af35b2d main + 109
    33  libdyld.dylib                       0x00000001107a99e9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

结果

image = Image.open(newest)
exif = image._getexif()
gps = {}
datebool = False
gpsbool = False
date = 'None'
time = 'None'
gpstext = 'None'
dmslat = 'None'
dmslon = 'None'

if exif is not None:
    for tag, entry in exif.items():                        #Import date and time from Exif
        datebool = True
        if TAGS.get(tag, tag) == 'DateTimeOriginal':
            date = entry[0:10]
            time = entry[11:19]
    for tag, entry in exif.items():                        #Check if the GPSInfo field exists
        if TAGS.get(tag,tag) == 'GPSInfo':
            gpsbool = True
            for e in entry:
                decoded = GPSTAGS.get(e,e)
                print (decoded)
                print(type(entry))
                gps[decoded] = entry[e]

由于e是从条目中提取的,如何从条目中索引特定的e会产生索引错误?我实际上是在为gps提取正确的数据吗?

1 个答案:

答案 0 :(得分:0)

entry = (3, 5, 7) for e in entry: print(e) 不会为条目中的值编制索引,而是迭代它们。例如:

3
5
7

将输出:

gps[decoded] = e

所以该行应该看起来像:

GPSTAGS

虽然我不确定entry行会变成什么样。如果您确实需要枚举enumerate()中的项目,那么您应该查看(令您惊讶的是,我确定)UIViews函数。