import usocket as socket import ssl with open('token') as f: token = f.readline().strip('\n') def send_msg(text, title=""): s = socket.socket() host = "ntfy.acorneroftheweb.com" port = 443 ai = socket.getaddrinfo(host, port) print("Address infos:", ai) addr = ai[0][-1] print("Connect address:", addr) s.connect(addr) s = ssl.wrap_socket(s) headers = """\ POST / HTTP/1.1\r Host: {host}\r Content-Type: application/json\r Authorization: Bearer {token} Accept: */*\r Connection: close\r Content-Length: {content_length}\r \r\n""" body = '{"topic": "d1", "message": "' + text + '", "title": "' + title + '"}' body_bytes = body.encode('ascii') header_bytes = headers.format( content_length=len(body_bytes), token=token, host=str(host) ).encode('iso-8859-1') payload = header_bytes + body_bytes print(payload) s.write(payload) print(s.read()) s.close() def main(): send_msg("Hello there") main()