emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Tornado Python

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

Tornado Python

Installieren
pip install tornado
Datei
app.py
Ausführen
python app.py
import asyncio
import base64
import re

import tornado.web

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


class PixelHandler(tornado.web.RequestHandler):
    def get(self) -> None:
        self.set_header("Content-Type", "image/gif")
        self.set_header("Cache-Control", "no-store")
        self.write(GIF)


async def main() -> None:
    # Tornado routes are regular expressions, so escape the literal path.
    app = tornado.web.Application([(re.escape("/pixel.gif"), PixelHandler)])
    app.listen(8080)
    await asyncio.Event().wait()


if __name__ == "__main__":
    asyncio.run(main())

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

Prüfen

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

Offizielle Website: Tornado

Mehr in Python