Python - TypeError: not all arguments converted during string formatting

Python - TypeError: not all arguments converted during string formatting

我写了下面的代码,不知道为什么在应用代码的时候报错,不知道是什么问题。

import datetime
now = datetime.datetime.now()
eventRootOids = ('1.3.6.1.4.1.11.2.17.19.2.2.%s')

EVENT_TRAP_VARBINDS = {
                'ApplicationId'      : tuple(['ApplicationId'] + [oid % 1 for oid in eventRootOids]),
                 Console'        : tuple(['Console'] + [oid% 2 for oid in eventRootOids]),
                       }

我的 ROOT OID 应该是 1.3.61.4.1.44.2.17.19.2.2.1/2/3 等等..)

TypeError: not all arguments converted during string formatting
                'ApplicationId'      : tuple(['ApplicationId'] + [oid % 1 for oid in eventRootOids]),

您在 eventRootOids = ('1.3.6.1.4.1.11.2.17.19.2.2.%s') 中漏掉了一个逗号;你写的方式不是元组。

import datetime

now = datetime.datetime.now()

eventRootOids = ('1.3.6.1.4.1.11.2.17.19.2.2.%s', )

EVENT_TRAP_VARBINDS = { 'ApplicationId' : 
    tuple(['ApplicationId'] + [oid % 1 for oid in eventRootOids]), 
    'Console' : tuple(['Console'] + [oid % 2 for oid in eventRootOids]), }

print(EVENT_TRAP_VARBINDS)

输出:

{'ApplicationId': 
    ('ApplicationId', '1.3.6.1.4.1.11.2.17.19.2.2.1'),
    'Console': ('Console', '1.3.6.1.4.1.11.2.17.19.2.2.2')
}