import requests
import json


def _post_req(url, email, password):
    """
    Posts non-graphql requests to ThreatPlaybook API Server. Currently used for:
        * Create User
        * Login
    :param url: ThreatPlaybook API URL
    :param email: E-mail of the User
    :param password: Password set by the User
    :return: Returns with response
    """
    headers = {'content-type': 'application/json'}
    auth = {"email": email, "password": password}
    try:
        r = requests.post(url=url, headers=headers, data=json.dumps(auth))
        if r.status_code == 500:
            return {'error': 'Server Error'}
        return r.json()
    except ConnectionError:
        return {'error': 'Unable to contact Threatplaybook API server'}