python 数据呈现_Python网站Django频道上的数据呈现

从python服务器向Django服务器发送数据。在

我的-websocket.pydef on_message(ws, message):

print (message)

def on_error(ws, error):

print ("eroror:", error)

def on_close(ws):

print ("### closed ###")

# Attemp to reconnect with 2 seconds interval

time.sleep(2)

initiate()

def on_open(ws):

print ("### Initiating new websocket connectipython my-websocket.pyon ###")

def run(*args):

for i in range(30000):

# Sending message with 1 second intervall

time.sleep(1)

ws.send("Hello %d" % i)

# ws.send(json.dumps("Hello %d" % i))

time.sleep(1)

ws.close()

print ("thread terminating...")

_thread.start_new_thread(run, ())

def initiate():

websocket.enableTrace(True)

ws = websocket.WebSocketApp("ws://localhost:8000/ws/power/room/",

on_message = on_message,

on_error = on_error,

on_close = on_close)

ws.on_open = on_open

ws.run_forever()

if __name__ == "__main__":

initiate()

我的Django频道的消费者是

消费者.py

^{pr2}$

错误WebSocket HANDSHAKING /ws/power/room/ [127.0.0.1:54591]

WebSocket CONNECT /ws/power/room/ [127.0.0.1:54591]

Exception inside application: Expecting value: line 1 column 1 (char 0)

File "C:\Program Files\Python37\lib\site-packages\channels\sessions.py", line 179, in __call__

return await self.inner(receive, self.send)

File "C:\Program Files\Python37\lib\site-packages\channels\middleware.py", line 41, in coroutine_call

await inner_instance(receive, send)

File "C:\Program Files\Python37\lib\site-packages\channels\consumer.py", line 59, in __call__

[receive, self.channel_receive], self.dispatch

File "C:\Program Files\Python37\lib\site-packages\channels\utils.py", line 52, in await_many_dispatch

await dispatch(result)

File "C:\Program Files\Python37\lib\site-packages\asgiref\sync.py", line 108, in __call__

return await asyncio.wait_for(future, timeout=None)

File "C:\Program Files\Python37\lib\asyncio\tasks.py", line 388, in wait_for

return await fut

File "C:\Program Files\Python37\lib\concurrent\futures\thread.py", line 57, in run

result = self.fn(*self.args, **self.kwargs)

File "C:\Program Files\Python37\lib\site-packages\channels\db.py", line 13, in thread_handler

return super().thread_handler(loop, *args, **kwargs)

File "C:\Program Files\Python37\lib\site-packages\asgiref\sync.py", line 123, in thread_handler

return self.func(*args, **kwargs)

File "C:\Program Files\Python37\lib\site-packages\channels\consumer.py", line 105, in dispatch

handler(message)

File "C:\Program Files\Python37\lib\site-packages\channels\generic\websocket.py", line 60, in websocket_receive

self.receive(text_data=message["text"])

File "C:\Users\Suleman\PycharmProjects\power\myChannels\consumers.py", line 41, in receive

text_data_json = json.loads(text_data)

File "C:\Program Files\Python37\lib\json\__init__.py", line 348, in loads

return _default_decoder.decode(s)

File "C:\Program Files\Python37\lib\json\decoder.py", line 337, in decode

obj, end = self.raw_decode(s, idx=_w(s, 0).end())

File "C:\Program Files\Python37\lib\json\decoder.py", line 355, in raw_decode

raise JSONDecodeError("Expecting value", s, err.value) from None

Expecting value: line 1 column 1 (char 0)

WebSocket DISCONNECT /ws/power/room/ [127.0.0.1:54591]

你可以从错误中看到,我可以在websocket之间进行握手,但是数据没有呈现在网页上。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值