title: Requests 01 tags: python web requests # Post Example Get requests are similar, but without the `data` payload, so if you understand how to `POST` in `requests`, then you basically know how to `GET` too. ```py import requests import access import json url = "http://localhost/path/to/a.php" cookies = { access.cookiename: acccess.cookievalue } namespace = "turtle" name = "dove" req = { "namespace": namespace, "name": name } r = requests.post(url,data=json.dumps(req),cookies=cookies) match r.status_code: case 200: try: reply = json.loads(r.text) value = reply["value"] print(value) except Exception as e: print("error",r,r.text,e,file=sys.stderr) case 404: print(f"{namespace}:{name} not found",file=sys.stderr) case 403: print(f"Access denied",file=sys.stderr) exit(1) ``` # Notes * At present you can't force IPv4 or IPv6. (I ended up using curl when this was necessary.)