Skip to content

Instantly share code, notes, and snippets.

@osvalr
Created February 16, 2017 01:32
Show Gist options
  • Save osvalr/165b76365ed18b9129a9596ca2976cc5 to your computer and use it in GitHub Desktop.
Save osvalr/165b76365ed18b9129a9596ca2976cc5 to your computer and use it in GitHub Desktop.
non-tested SUNAT
#!/bin/python
##
## This code have been taken from, and isn't tested yet by myself
## https://codeshare.io/nQXtS
## https://gitter.im/msolorzano/sunat2015
##
from suds.client import Client
from suds.wsse import *
import requests
import suds_requests
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 = ''
password = ''
session = requests.session()
session.auth = (username, password)
WSDL_URL = 'https://www.sunat.gob.pe/ol-ti-itcpgem-sqa/billService?wsdl'
client = Client(WSDL_URL, faults=False, cachingpolicy=1, location=WSDL_URL, transport=suds_requests.RequestsTransport(session))
addSecurityHeader(client, username, password)
result = client.service.methodName(Inputs)
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment