import urllib.request import urllib.parse import urllib.error URL = "https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP" soap_request = """ TEST EMPRESA SL 53950250R 1.0 53950250R FV2026/TEST001 17-04-2026 TEST EMPRESA SL F1 Factura de prueba test 01 S1 01 100.00 21.00 21.00 121.00 S TEST API 53950250R TEST-API 1 1.0 1 S 17-04-2026T12:00:00 SHA-256 0A1B2C3D4E5F6 """ ctx = urllib.request.ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = urllib.request.ssl.CERT_NONE headers = { "Content-Type": "text/xml; charset=utf-8", "SOAPAction": "" } print("Testing AEAT without certificate (just headers)...") req = urllib.request.Request(URL, data=soap_request.encode('utf-8'), headers=headers) try: opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=ctx)) response = opener.open(req, timeout=30) print(f"Status: {response.status}") print(f"Response: {response.read().decode('utf-8')[:1500]}") except urllib.error.HTTPError as e: print(f"HTTP Error: {e.code}") print(f"Body: {e.read().decode('utf-8')[:1500]}") except Exception as e: print(f"Error: {type(e).__name__}: {e}")