我在尝试使用Python中的SUDS访问WS时遇到此错误。
知道我做错了什么吗? (是的,我对Python很陌生)
Python代码
# -*- coding: utf-8 -*-
from suds.client import Client
from apscheduler.scheduler import Scheduler
import datetime
import logging
from email.header import Header
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP_SSL
from colorlog import ColoredFormatter
# Configurações do Log
logging.basicConfig(format='%(asctime)s - %(message)s', datefmt='%d/%m/%Y %H:%M:%S', filename='ConfirmarPedidoSmsBroker-Test.log',level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler())
now = datetime.datetime.now()
#Informações para o consumo do WS
WSDL_URL = "http://123.168.1.132:8084/abc-ws-provider/AbcBrokerBSv1.0?wsdl"
#Criações dos tipos para gerar o objeto complexo
class Evale(object):
codigoDeAutorizacao = 1234567
class Cliente (object):
identificacaoDoCliente = 12345
codigoDoCliente = 101010
razaoSocial = "None"
class Telefone (object):
ddd = 21
numero = 1234-5678
class Contato (object):
telefone = Telefone()
class HorariosDeAtendimento (object):
diaDaSemana = "Sunday"
horaInicial = "07:30:00"
horaFinal = "20:00:00"
class TipoDeAtendimentoRealizado (object):
horariosDeAtendimento = HorariosDeAtendimento()
class Revenda (object):
cliente = Cliente()
identificacaoDoEndereco = 987654
codigoDoEndereco = 8765567
numeroDoDocumento = "2312341"
filialDoDocumento = 0009
digitoDoDocumento = 32
class RevendaPrincipal(object):
revenda = Revenda()
class RevendaAlternativa(object):
revenda = Revenda()
class EnderecoDoSolicitante(object):
logradouro = "Street Test"
numeroDoEndereco = 80
complemento = "Penth"
municipio = "New York"
bairro = "Brooklin"
cep = "74123"
estado = "NY"
class PedidoSms(object):
identificacaoDaTransacao = 1010
evale = Evale()
revendaPrincipal = RevendaPrincipal()
revendaAlternativa = RevendaAlternativa()
enderecoDoSolicitante = EnderecoDoSolicitante()
latitudeDoEnderecoDoSolicitante = -92.123443
longitudeDoEnderecoDoSolicitante = -81.98765
class ConfirmarPedidoSmsBrokerRequest(object):
pedidoSms = PedidoSms()
class ConfirmarPedidoSmsBroker_InputVariable (object):
confirmarPedidoSmsBrokerRequest = ConfirmarPedidoSmsBrokerRequest()
class Input (object):
confirmarPedidoSmsBroker_InputVariable = ConfirmarPedidoSmsBroker_InputVariable()
# Método que chama o serviço
def sendRequestToService():
confPedido = Input()
logging.info("ConfirmarPedidoSmsBroker-Test at " + str(now))
logging.info("WSDL_URL " + WSDL_URL)
logging.info("Passing URL to Client")
client = Client(WSDL_URL)
logging.info("Trying to access the service")
response = client.service.confirmarPedidoSmsBroker(confPedido)
logginf.info(response)
if __name__ == '__main__':
sendRequestToService()
这是我每次尝试运行时都会遇到的错误。
06/02/2014 17:06:17 - ConfirmarPedidoSmsBroker-Test at 2014-02-06 17:06:17.443663
06/02/2014 17:06:17 - WSDL_URL http://111.168.1.132:8084/abc-ws-provider/AbcBrokerBSv1.0?wsdl
06/02/2014 17:06:17 - Passing URL to Client
06/02/2014 17:06:17 - Import:0x10ab61d10, imported schema (http://www.abcdef.com.br/Abab/BO/v3) at (http://123.168.1.132:8084/../../../../../Abc/Def/Somethingv3.xsd), failed
Traceback (most recent call last):
File "build/bdist.macosx-10.9-intel/egg/suds/xsd/sxbasic.py", line 560, in download
d = reader.open(url)
File "build/bdist.macosx-10.9-intel/egg/suds/reader.py", line 79, in open
d = self.download(url)
File "build/bdist.macosx-10.9-intel/egg/suds/reader.py", line 95, in download
fp = self.options.transport.open(Request(url))
File "build/bdist.macosx-10.9-intel/egg/suds/transport/https.py", line 60, in open
return HttpTransport.open(self, request)
File "build/bdist.macosx-10.9-intel/egg/suds/transport/http.py", line 64, in open
raise TransportError(str(e), e.code, e.fp)
TransportError: HTTP Error 400: Bad Request
答案 0 :(得分:0)
您的WSDL服务似乎正在响应您传递的请求的400错误(可能是缺少必需的参数等)。请尝试add debug logging这样:
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
在执行此操作后,再试一次(您只需打开交互式python shell并粘贴代码,启用日志记录并调用sendRequestToService
函数。
请用更新修改您的问题,我会酌情修改我的答案。