<commit_before>import requests
import uuid
import json
import os

RPI_SERVER = 'http://localhost:8000'
RPI_SECRET_KEY = 'topkeklol'


def get_mac():
    mac_addr = hex(uuid.getnode()).replace('0x', '')
    return ':'.join(mac_addr[i: i + 2] for i in range(0, 11, 2))


def get_hostname():
    url = RPI_SERVER + '/rpi/api/'
    client = requests.session()
    client.get(RPI_SERVER + '/admin/login/')
    csrftoken = client.cookies['csrftoken']
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Referer': RPI_SERVER + '/admin',
    }
    mac = get_mac()
    data = {
        'mac_address': mac,
        'csrfmiddlewaretoken': csrftoken,
        'secret_key': 'topkeklol'
    }
    hostname = json.loads(client.post(url, headers=headers, data=data).text)['name']  # Laster hele json-strengen
    print(hostname)
    return hostname if 10 > len(hostname) > 0 else None


if __name__ == '__main__':
    hostname = get_hostname()<commit_msg>Better error handling<commit_after>import requests
import uuid
import json
import os

RPI_SERVER = 'http://localhost:8000'
RPI_SECRET_KEY = 'topkeklol'


def get_mac():
    mac_addr = hex(uuid.getnode()).replace('0x', '')
    return ':'.join(mac_addr[i: i + 2] for i in range(0, 11, 2))


def get_hostname():
    url = RPI_SERVER + '/rpi/api/'
    client = requests.session()
    client.get(RPI_SERVER + '/admin/login/')
    csrftoken = client.cookies['csrftoken']
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Referer': RPI_SERVER + '/admin',
    }
    mac = get_mac()
    data = {
        'mac_address': mac,
        'csrfmiddlewaretoken': csrftoken,
        'secret_key': 'topkeklol'
    }
    try:
        hostname = json.loads(client.post(url, headers=headers, data=data).text)['name']  # Laster hele json-strengen
        return hostname
    except json.decoder.JSONDecodeError:
        return None


if __name__ == '__main__':
    hostname = get_hostname()
{'fraction_non_alphanumeric': 0.14676113360323886, 'fraction_numerical': 0.011639676113360324, 'mean_word_length': 3.1446540880503147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4892917', 'n_tokens_mistral': 718, 'n_tokens_neox': 702, 'n_words': 145}