Back to General discussions forum
Posting the 'token', 'start' and 'geese' fields to the server results in a 500 error.
Code used for interacting with the server.
import requests
from requests.exceptions import HTTPError, RequestException
URL = "http://2.59.218.221/foxgeese.php"
TOKEN = "Hm1QM+FSIiACW/+GG5M4XjE0"
def send_text(data):
body_items = [("token", TOKEN)] + list(data.items())
body = "\n".join(f"{k}: {v}" for k, v in body_items)
headers = {"Content-Type": "text/plain"}
try:
response = requests.post(URL, data=body, headers=headers, timeout=30)
response.raise_for_status()
except HTTPError as e:
print(f"HTTP error occurred: {e} (Status: {response.status_code})")
print(f"Response body: {response.text}")
raise
except RequestException as e:
print(f"Connection or timeout error occurred: {e}")
raise
resp = {}
for line in response.text.splitlines():
if ": " in line:
k, v = line.split(": ", 1)
resp[k.strip()] = v.strip()
return resp
print("#1", send_text({}))
print("#2", send_text({"start": 123}))
print("#3", send_text({"geese": "du"}))
print("#4", send_text({"start": 123, "geese": "du"}))
Output:
#1 {'error': 'You are trying to continue the task which was not started'}
#2 {'message': 'started', 'error': 'No "geese" in your request?'}
#3 {'error': 'The game is not started yet!'}
HTTP error occurred: 500 Server Error: Internal Server Error for url: http://2.59.218.221/foxgeese.php (Status: 500)