Skip to content

Instantly share code, notes, and snippets.

@umiphos
Last active October 23, 2018 03:18
Show Gist options
  • Save umiphos/a35425670b43e722ed48ca99762c2fa2 to your computer and use it in GitHub Desktop.
Save umiphos/a35425670b43e722ed48ca99762c2fa2 to your computer and use it in GitHub Desktop.
suds and sunat for peru
#!/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 = 'MODDATOS'
password = 'MODDATOS'
session = requests.session()
session.auth = (username, password)
WSDL_URL = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
client = Client(WSDL_URL, faults=False, cachingpolicy=1, location=WSDL_URL)
addSecurityHeader(client, username, password)
fileName = ""
fileContent = "This is the base64 file"
import pdb;pdb.set_trace()
get_file = client.service.sendBill(fileName, fileContent)
import sys
from suds import client
from suds.wsse import Security, UsernameToken as usernameToken
from suds.sudsobject import asdict
from suds import WebFault
username = 'MODDATOS'
password = 'MODDATOS'
wsdl_url = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
client = client.Client(wsdl_url)
security = Security()
token = usernameToken(username, password)
security.tokens.append(token)
client.set_options(wsse=security)
xml = open('xxxxxxxxxxx-01-FE01-00000001.zip')
result = client.service.sendBill("xxxxxxxxxxx-01-FE01-00000001.zip", xml.read())
import sys
from suds import client
from suds.wsse import Security, UsernameToken as usernameToken
from suds.sax.text import Raw
from suds.sudsobject import asdict
from suds import WebFault
username = ''
password = ''
wsdl_url = ''
client = client.Client(wsdl_url)
security = Security()
token = usernameToken(username, password)
security.tokens.append(token)
contentFile = ''
client.set_options(wsse=security)
import pdb;pdb.set_trace()
result = client.service.sendBill(fileName, contentFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment