Python suds Sunat example.

#!/usr/bin/python
from suds.client import Client
from suds.wsse import *
import requests
import base64
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
#logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
#logging.getLogger('suds.wsse').setLevel(logging.DEBUG)

def addSecurityHeader(client, username, password):
    security = Security()
    userNameToken = UsernameToken(username, password)
    timeStampToken = Timestamp(validity=600)
    security.tokens.append(userNameToken)
    security.tokens.append(timeStampToken)
    client.set_options(wsse=security)
username = '20600999806MODDATOS'
password = 'moddatos'
session = requests.session()
session.auth = (username, password)

WSDL_URL = 'https://www.sunat.gob.pe/ol-ti-itcpgem-beta/billService?wsdl'
client = Client(WSDL_URL, faults=False, cachingpolicy=1, location=WSDL_URL)
addSecurityHeader(client, username, password)

# Send File
f = open('/tmp/xml/20600999806-01-F001-1.zip', 'rb')
data_file = f.read()

get_file = client.service.sendBill("20600999806-01-F001-1.zip", base64.b64encode(str(data_file)))

# Save file
get_file_decode = base64.b64decode(str(get_file[1]))
f = open('/tmp/xml/R-20600999806-01-F001-1.zip', 'w')

f.write(get_file_decode)

f.close()