File size: 460 Bytes
3932407
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import requests


def assert_http_ok(response: requests.Response):
    if response.status_code != 200:
        base_msg = f"HTTP request to {response.url} failed with status code {response.status_code} after {response.elapsed.total_seconds()}s"
        if not response.content:
            raise Exception(f"{base_msg} and without response body")
        else:
            raise Exception(
                f"{base_msg} with response body:\n{response.json()}")