import requests import time import random while True: url = "https://capi.t-mobile.nl/xxxxe36xxxx/customer/1.xxxx87xx/subscription/xxxx188xxxx/roamingbundles" payload = "{\"bundles\":[{\"buyingCode\":\"A0DAY\"}]}" headers = { 'accept': 'application/json,application/vnd.capi.tmobile.nl.roamingbundles.v3+json', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'nl-nl', 'authorization': 'Bearer xxx92xx61xxxxxc3fxxx4xx43xxxxca1', 'connection': 'keep-alive', 'content-length': '36', 'content-type': 'application/json', 'cookie': 'crtK=v1V9xxxx__dWb; _ga=GA1.2.xxxxxxxxxx.xxxxxxxxx; bc_tsxxxx=3; tm_cookie_setting=Analytics', 'host': 'capi.t-mobile.nl', 'user-agent': 'My%20T%E2%80%91Mobile/11648 CFNetwork/1121.2.2 Darwin/19.2.0' } response = requests.request("POST", url, headers=headers, data = payload) print(response.text.encode('utf8')) #print(response.status_code) if response.status_code == 500: print('The provided buying code isn''t available for purchase.') time.sleep(random.randrange(30, 40)) elif response.status_code == 202: print('Success, 1GB added!') time.sleep(random.randrange(30, 40)) else: print(response.status_code) time.sleep(random.randrange(30, 40))