Bonjour
J’ai ce code qui me permet d’établir une connexion websoket.
from aiohttp import web
routes = web.RouteTableDef()
ws = None
@routes.get("/ws")
async def websocket(request):
global ws
ws = Websocket(request)
print("Connected")
await ws
print("Disconnected")
return ws.ws
@routes.post("/connect")
async def connect(request):
global ws
if ws is None:
raise web.HTTPInternalServerError("There is no connected")
clientOffer = await request.json()
ws.put_nowait(clientOffer)
Response = await ws.get()
return web.json_response(Response)
async def cleanup(app=None):
global ws
if ws is not None:
c = ws.close()
if c is not None:
await c
app = web.Application()
app.add_routes(routes)
app.on_shutdown.append(cleanup)
web.run_app(app,host='xx.xx.xx.xx', port=5000)
Il marche bien en local mais si je tente de le joindre depuis une page web externe j’ai un erreur de ce type
Access to fetch at 'https://unautre.site' from origin 'https://mon.site' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Après pas mal de recherche je suis tomber sur aiohttp-cors mais j’ai besoin d’aide pour l’ajouter à mon code.
+0
-0