import re


def get_csrf_token(res):
    """Extract the CSRF token from a response."""
    for header in res.headers:
        m = re.search('token=(.+?);', header[1])
        if m:
            return m.group(1)
    raise RuntimeError('Could not find CSRF token in response headers: ' + str(res.headers))