Python2.7.6针对问题的问题

Python2.7.6针对问题的问题,python,traceback,Python,Traceback,嗨,我用python 2.7.6编写了这些代码 但不会正确执行,总是给我错误。。。 请帮帮我 if __name__ == '__main__': channel=None devices = finddevices() for d in devices: ser=findservices(d[0]) for s in ser: print s if 'OBEX Object Push' in

嗨,我用python 2.7.6编写了这些代码 但不会正确执行,总是给我错误。。。 请帮帮我

if __name__ == '__main__':
    channel=None
    devices = finddevices()
    for d in devices:
        ser=findservices(d[0])
        for s in ser:
            print s
            if 'OBEX Object Push' in s[2]:
                channel=s[1]
        obex.sendfile(d[0], channel, '/home/mobile.jar')
并指出:

('00:E3:B2:0C:2E:2B', 2, 'Headset Gateway')
('00:E3:B2:0C:2E:2B', 3, 'Handsfree Gateway')
('00:E3:B2:0C:2E:2B', 4, 'Sim Access Server')
('00:E3:B2:0C:2E:2B', 23, 'AV Remote Control Target')
('00:E3:B2:0C:2E:2B', 25, 'Advanced Audio')
('00:E3:B2:0C:2E:2B', 15, 'Android Network Access Point')
('00:E3:B2:0C:2E:2B', 15, 'Android Network User')
('00:E3:B2:0C:2E:2B', 19, 'OBEX Phonebook Access Server')
('00:E3:B2:0C:2E:2B', 12, 'OBEX Object Push')
Traceback (most recent call last):
  File "/home/abbas/workspace/Bluetooth Module/package/test.py", line 21, in <module>
    obex.sendfile(d[0], channel, '/home/abbas/mobile.jar')
  File "/usr/lib/pymodules/python2.7/lightblue/_obex.py", line 234, in sendfile
    raise TypeError("channel must be int, was %s" % type(channel))
TypeError: channel must be int, was <type 'NoneType'>
('00:E3:B2:0C:2E:2B',2'耳机网关')
('00:E3:B2:0C:2E:2B',3'免提网关')
('00:E3:B2:0C:2E:2B',4'Sim卡接入服务器')
('00:E3:B2:0C:2E:2B',23'视听遥控目标')
('00:E3:B2:0C:2E:2B',25,“高级音频”)
('00:E3:B2:0C:2E:2B',15'安卓网络接入点')
('00:E3:B2:0C:2E:2B',15'安卓网络用户')
('00:E3:B2:0C:2E:2B',19'OBEX电话簿访问服务器')
('00:E3:B2:0C:2E:2B',12'OBEX对象推送')
回溯(最近一次呼叫最后一次):
文件“/home/abbas/workspace/Bluetooth Module/package/test.py”,第21行,在
sendfile(d[0],通道“/home/abbas/mobile.jar”)
文件“/usr/lib/pymodules/python2.7/lightblue/_obex.py”,第234行,在sendfile中
raise TypeError(“通道必须是int,was%s”%type(通道))
TypeError:通道必须是int,was
为什么我的频道没有?
为什么我的if条件为非真?

三种可能性:
s[1]
None
,条件总是
False
,或者
频道在未显示的代码中发生了某种变化。在调用
sendfile
之前尝试打印
channel
。根据日志,s[1]似乎是12,条件似乎是True@njzk2我刚刚编辑了这个,哈哈。增加了第三种可能性。我糊涂了!!!!!!!!!!!!!!!!!!!!!!当我在debug mod中运行这个脚本并设置break piont。。一切都很好,每一个想法都很好!!!!!!!!!!!!您确定它不会发送一次文件,然后在下一个设备上失败吗?例如:在第一台设备上,一切正常,您可以打印出
findservices()
返回的各种项目。但是在第二个设备上,您的
findservices()
调用返回一个空列表,因此内部for循环永远不会执行,您直接跳转到
obex.sendfile()
调用,该调用失败,出现错误。