Python

Fastapi

FastAPI - Dependencies and Custom Headers Source https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-in-path-operation-decorators/ Code from fastapi import Depends, FastAPI, Header, HTTPException app = FastAPI() async def verify_token(x_token: str = Header()): if x_token != "fake-super-secret-token": raise HTTPException(status_code=400, detail="X-Token header invalid") async def verify_key(x_key: str = Header()): if x_key != "fake-super-secret-key": raise HTTPException(status_code=400, detail="X-Key header invalid") return x_key @app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)]) async def read_items(): return [{"item": "Foo"}, {"item": "Bar"}] Test’s Failed no Custom Header curl -s http://localhost/api/items/ |jq { "detail": [ { "loc": [ "header", "x-token" ], "msg": "field required", "type": "value_error.

Little Mail Validator in Python

wrote a little Mail Adresse Validator in Python. use it, modify it, like it … best practice for python is to use a virtual env like Poetry (or virtualenv) and add the “email-validator” module like this: poetry add email-validator Code few lines of code … #!/usr/bin/env python3 from email_validator import validate_email, EmailNotValidError ok=[] nok=[] emails = [ "my+address@mydomain.tld", "hans@dampf.ch", "gott@welt.net", "adsf@asdf.com", "asf.asdf", "franz!mueller@abc.com", "asdf@asdf.adf" ] print ("\nMy Little Mail Validator\n") for email in emails: try: # Validate.

Python

Python Snippets RealPython Best Practices: https://realpython.com/tutorials/best-practices/ Remove a substring from the end of a string url = "abcdc.com" url.removesuffix(".com") # Returns 'abcdc' url.removeprefix("abcdc.") # Returns 'com' or url = "abcdc.com" if url.endswith(".com"): url = url[:-4] or regex import re url = "abcdc.com" url = re.sub("\.com$", "", url) Modul ‘ping3’ “Permission Denied” on Linux https://github.com/kyan001/ping3/blob/master/TROUBLESHOOTING.md#permission-denied-on-linux echo "# allow all users to create icmp sockets" > /etc/sysctl.d/ping_group.conf echo "net.ipv4.ping_group_range=0 2147483647" > /etc/sysctl.d/ping_group.conf sysctl net.