|
@ -25,6 +25,7 @@ def get_state(min_round: int, args) -> Tuple[Optional[dict], float]: |
|
|
logger.warning(f"Server error: {r.status_code} {r.reason}") |
|
|
logger.warning(f"Server error: {r.status_code} {r.reason}") |
|
|
return None, TIME_BEFORE_RETRY |
|
|
return None, TIME_BEFORE_RETRY |
|
|
|
|
|
|
|
|
|
|
|
state = r.json() |
|
|
# also retry if the server is not willing to give us the state yet |
|
|
# also retry if the server is not willing to give us the state yet |
|
|
if state["status"] == "waiting": |
|
|
if state["status"] == "waiting": |
|
|
logger.info("Server is busy.") |
|
|
logger.info("Server is busy.") |
|
@ -33,7 +34,6 @@ def get_state(min_round: int, args) -> Tuple[Optional[dict], float]: |
|
|
logger.info("Round didn't start yet.") |
|
|
logger.info("Round didn't start yet.") |
|
|
return None, state["wait"] |
|
|
return None, state["wait"] |
|
|
|
|
|
|
|
|
state = json.loads(r.json()) |
|
|
|
|
|
logger.info("Received new state.") |
|
|
logger.info("Received new state.") |
|
|
return state, 0 |
|
|
return state, 0 |
|
|
|
|
|
|
|
@ -43,7 +43,7 @@ def send_turn(turn: dict, round: int, args) -> bool: |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
r = requests.post( |
|
|
r = requests.post( |
|
|
f"{args.server}/api/state", |
|
|
f"{args.server}/api/action", |
|
|
params={ |
|
|
params={ |
|
|
"game": args.game, |
|
|
"game": args.game, |
|
|
"token": args.token, |
|
|
"token": args.token, |
|
@ -61,7 +61,7 @@ def send_turn(turn: dict, round: int, args) -> bool: |
|
|
# print errors |
|
|
# print errors |
|
|
# because such errors are caused by the submitted turn, |
|
|
# because such errors are caused by the submitted turn, |
|
|
# retrying will not help, so return True |
|
|
# retrying will not help, so return True |
|
|
response = json.loads(r.json()) |
|
|
response = r.json() |
|
|
if response["status"] == "ok": |
|
|
if response["status"] == "ok": |
|
|
logger.info("Turn accepted.") |
|
|
logger.info("Turn accepted.") |
|
|
elif response["status"] == "too_late": |
|
|
elif response["status"] == "too_late": |
|
@ -73,6 +73,6 @@ def send_turn(turn: dict, round: int, args) -> bool: |
|
|
f" {member}: {error}" |
|
|
f" {member}: {error}" |
|
|
for member, error in response["errors"].items() |
|
|
for member, error in response["errors"].items() |
|
|
] |
|
|
] |
|
|
logger.error(f"Member errors:\n{'\n'.join(member_errors)}") |
|
|
logger.error("Member errors:\n" + "\n".join(member_errors)) |
|
|
|
|
|
|
|
|
return True |
|
|
return True |
|
|