emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

aiohttp Python

Ein Python-Snippet für aiohttp, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

aiohttp Python

Installieren
pip install aiohttp
Datei
server.py
Ausführen
python server.py
import base64

from aiohttp import web

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

routes = web.RouteTableDef()


@routes.get("/pixel.gif")
async def pixel(request: web.Request) -> web.Response:
    return web.Response(
        body=GIF, content_type="image/gif", headers={"Cache-Control": "no-store"}
    )


app = web.Application()
app.add_routes(routes)

if __name__ == "__main__":
    web.run_app(app, port=8080)

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

curl -sI http://localhost:8080/pixel.gif

Offizielle Website: aiohttp

Mehr in Python