我正在尝试使用 xmlrpclib python 的库来执行 XMP-RPC,但我得到了
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 1, column 1
这是带有参数的字典:
{'cliente_chave': 'hUi238sh328sjk37Hms8Kisjeg9',
'cliente_codigo': 164,
'imovel_bairro': u'Renascen\xe7a',
'imovel_banheiros': u'5',
'imovel_cidade': u'S\xe3o Lu\xeds - MA',
'imovel_codigo_imobiliaria': u'757',
'imovel_descricao': u'\n\t\t\t\n\t\t\tCasa em otima localiza\xe7\xe3o ideal tanto para empresas quanto para moradia tendo:\r\nTerra\xe7o\r\nSala Ampla para 03 ambientes\r\nLavabo\r\nHall\r\n03 su\xedtes\r\nEscritorio\r\nCozinha\r\nQuintaL\r\n\xc1rea de Servi\xe7o\r\nDCE\r\nGaragem coberta para 02 carros\r\nPort\xe3o eletronico\r\nCisterna\r\nNascente',
'imovel_estado': 'MA',
'imovel_negociacao': 'venda',
'imovel_novo': False,
'imovel_quartos': u'3',
'imovel_subtipo': u'padr\xe3o',
'imovel_suites': u'3',
'imovel_tipo': u'casa',
'imovel_vagas': u'2',
'imovel_valor': u' 480.000,00',
'url': 'http://www.estiloma.com.br/imoveis/para-venda/em-sao-luis/no-bairro-renascenca/casa-padrao/id-774.html'}
这是异常的回溯:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/Twisted-12.2.0-py2.7-macosx-10.8-intel.egg/twisted/internet/defer.py", line 551, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/Users/bslima/Documents/Aptana Studio 3 Workspace/aqueleimovel/aqueleimovel/pipelines.py", line 31, in process_item
result = server.salvar_imovel(dict(item))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1575, in __request
verbose=self.__verbose
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1467, in parse_response
p.feed(data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 557, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 1, column 1
我只对字符串使用 UTF-8,如果没有运气,我会尝试编码或解码为 UTF-8。我也尝试用谷歌搜索,但没有成功。有人见过这个吗?
哦,这是客户端代码:
server = ServerProxy(uri=settings.RPC_SERVER, verbose=True)
server.salvar_imovel(item)
我在这里先向您的帮助表示感谢。
正如我评论的那样,ExpatError 在响应对象中。谢谢