import urllib.request import urllib.parse URL = "https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP" soap_request = """ TEST 53950250R 1.0 53950250R FV2026/001 17-04-2026 TEST EMPRESA F1 Factura de prueba 01 S1 01 100.00 21.00 21.00 121.00 S TEST 53950250R TEST 1 1.0 1 S 17-04-2026T12:00:00 SHA-256 TESTHASH """ headers = { "Content-Type": "text/xml; charset=utf-8", "SOAPAction": "" } print("Enviando a AEAT test...") print(f"URL: {URL}") req = urllib.request.Request(URL, data=soap_request.encode('utf-8'), headers=headers) try: with urllib.request.urlopen(req, timeout=30) as response: print(f"\nStatus: {response.status}") content = response.read().decode('utf-8') print(f"\nResponse:\n{content[:1500]}") except urllib.error.HTTPError as e: print(f"HTTP Error: {e.code}") print(f"Response: {e.read().decode('utf-8')[:1500]}") except urllib.error.URLError as e: print(f"URL Error: {e.reason}")