python代码中的错误

时间:2011-02-05 01:24:43

标签: python

请查看最后的代码和错误。

from brisa.core.reactors import install_default_reactor
reactor = install_default_reactor()
print reactor

import os

from brisa.upnp.device import Device, Service
from brisa.upnp.device.service import StateVariable


class BinaryLight(Device):

    def __init__(self):
        Device.__init__(self,
                        'urn:schemas-upnp-org:device:BinaryLight:1',
                        'Binary Light device')


class SwitchPower(Service):

    def __init__(self):
        Service.__init__(self,
                         'SwitchPower',
                         'urn:schemas-upnp-org:service:SwitchPower:1',
                         '',
                         os.getcwd() + '/SwitchPower-scpd.xml')
        self.target = False
        self.status = False
        self.varin = StateVariable(self, "Status",
                              True, False, "boolean")
        self.varin.subscribe_for_update(self.varUpdateCallback)
        self.add_state_variable(self.varin)

    def varUpdateCallback(self, name, value):
        print name, 'was updated to', value

    def SetTarget(self, *args, **kwargs):
        self.target = kwargs['NewTargetValue']
        self.status = self.target
        self.set_state_variable('Status', self.target)
        print 'Light switched ', {'1': 'on', '0': 'off'}.get(self.target, None)
        return {}

    def GetTarget(self, *args, **kwargs):
        return {'RetTargetValue': self.target}

    def soap_GetStatus(self, *args, **kwargs):
        return {'ResultStatus': self.status}


if __name__ == '__main__':
    device = BinaryLight()
    device += SwitchPower()

    # Start device
    device.start()

    # Setup main loop
    reactor.add_after_stop_func(device.stop)
    reactor.main()

我收到错误: -

ankit @ ubuntu:〜/ Desktop $ python binary_light.py你能告诉我我在哪里做错了吗?

Error:
Traceback (most recent call last):
  File "binary_light.py", line 8, in <module>
    from brisa.upnp.device import Device, Service
  File "/usr/local/lib/python2.6/dist-packages/brisa/upnp/device/__init__.py", line 8, in <module>
    from brisa.upnp.device.device import Device
  File "/usr/local/lib/python2.6/dist-packages/brisa/upnp/device/device.py", line 10, in <module>
    from brisa.core import log, config, webserver, network
  File "/usr/local/lib/python2.6/dist-packages/brisa/core/webserver.py", line 39, in <module>
    raise RuntimeError('Network is down.')
RuntimeError: Network is down.

新错误:

Traceback (most recent call last):
  File "binary_light.py", line 57, in <module>
    device = BinaryLight()
  File "binary_light.py", line 21, in __init__
    'Binary Light device')
  File "/usr/local/lib/python2.6/dist-packages/brisa/upnp/device/device.py", line 83, in __init__
    additional_headers=additional_ssdp_headers)
  File "/usr/local/lib/python2.6/dist-packages/brisa/upnp/ssdp.py", line 71, in __init__
    data_callback=self._datagram_received)
  File "/usr/local/lib/python2.6/dist-packages/brisa/core/network_listeners.py", line 188, in __init__
    self._create_socket(shared_socket)
  File "/usr/local/lib/python2.6/dist-packages/brisa/core/network_listeners.py", line 227, in _create_socket
    "Couldn't bind address")
brisa.core.network_listeners.CannotListenError

请让我知道我在哪里做错了?

3 个答案:

答案 0 :(得分:0)

这不是错误。在第3行,您将打印对象“reactor”。

答案 1 :(得分:0)

正如其他人所说,这不是错误。但是,我的猜测是你有错误,某些地方出了问题某处或者你不会在这里打扰。尝试删除print语句。如果您再收到“错误”,请告诉我们。

答案 2 :(得分:0)

(回应更新的问题)

嗯,错误表明找不到网络。

查看the code,尝试在脚本开头执行此操作:

import brisa
brisa.__enable_offline_mode__ = True
from brisa.core.reactors import install_default_reactor