第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何將 Javascript 客戶端連接到蟒蛇-套接字 IO 服務(wù)器?

如何將 Javascript 客戶端連接到蟒蛇-套接字 IO 服務(wù)器?

Go
德瑪西亞99 2022-10-05 09:30:46
我剛剛開始使用Python-SocketIO,我創(chuàng)建了一個(gè)示例服務(wù)器,它看起來像這樣:import eventletimport socketiosio = socketio.Server()app = socketio.WSGIApp(sio, static_files={    '/': {'content_type': 'text/html', 'filename': 'index.html'}})@sio.on('connect')def connect(sid, environ):    print('connect ', sid)@sio.on('msg')def message(sid, data):    print('message ', data)@sio.on('disconnect')def disconnect(sid):    print('disconnect ', sid)if __name__ == '__main__':    eventlet.wsgi.server(eventlet.listen(('', 5000)), app)然后,我有一個(gè)HTML文件,它正在Django應(yīng)用程序上運(yùn)行,我想將該客戶端連接到我的Python-SocketIO服務(wù)器:<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script><script>socket = io.connect('');socket.on('connect',function() {  console.log('Client has connected to the server!');});socket.on('msg',function(data) {  console.log('Received a message from the server!',data);});socket.on('disconnect',function() {  console.log('The client has disconnected!');});// Sends a message to the server via socketsfunction send(message) {  socket.send('msg',message);};</script>問題是,在我的客戶端,我不斷收到以下錯(cuò)誤:Access to XMLHttpRequest at 'http://localhost:5000/socket.io/?EIO=3&transport=polling&t=N5eSEa2' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.localhost:5000/socket.io/?EIO=3&transport=polling&t=N5eSEa2:1 Failed to load resource: net::ERR_FAILED我的詹戈服務(wù)器正在運(yùn)行。任何人都可以幫我找到我做錯(cuò)了什么嗎?on http://127.0.0.1:8000/
查看完整描述

1 回答

?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

在服務(wù)器上設(shè)置 CORS 標(biāo)頭:

sio = socketio.Server(cors_allowed_origins='*')

()


查看完整回答
反對 回復(fù) 2022-10-05
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號