gpt4 book ai didi

python - 在 Python 中发布 HTTP : Reserved XML Name. 行 : 2, 字符:40

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:01 24 4
gpt4 key购买 nike

我正在尝试将德国支付提供商 SOFORT Überweisung 集成到我自己的 Python 编码在线商店中。他们没有可用的 Python 库,他们的支持也无法回答问题所在。

他们要求在第一步中像这样发布 XML:

<?xml version="1.0" encoding="UTF-8" ?>
<multipay>
<project_id>WHITEOUT</project_id>
<amount>24.51</amount>
<currency_code>EUR</currency_code>
<reasons>
<reason>Testueberweisung</reason>
<reason>-TRANSACTION-</reason>
</reasons>
<success_url>http://WHITEOUT?stage=paymentAuthorizationSuccessful</success_url>
<success_link_redirect>1</success_link_redirect>
<abort_url>http://WHITEOUT?stage=paymentCancelled</abort_url>
<su />
</multipay>

我的实现代码如下:

response = PostHTTP(url = self.endpoint, data = xml, authentication = '%s:%s' % (self.clientNumber, self.APIkey), contentType = 'application/xml; charset=UTF-8')

使用以下函数:

def PostHTTP(url, values = [], data = None, authentication = None, contentType = None):
u"""\
POST HTTP responses from the net. Values are dictionary {argument: value}
Authentication as "username:password"
"""

import urllib, urllib2, base64

if values:
data = urllib.urlencode(values)

headers = {}


if contentType:
headers["Content-Type"] = contentType
headers["Accept"] = contentType

if authentication:
base64string = base64.encodestring(authentication)
headers["Authorization"] = "Basic %s" % base64string

request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
return response.read()

他们的服务器不断响应

<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>
<code>7000</code>
<message>Reserved XML Name. line: 2, char: 40</message>
</error>
</errors>

我不明白。有什么想法吗?

更新:

他们的支持再次得到答复。看来错误确实在服务器端,需要更改,因为当我遗漏第一行时 <?xml ?>响应符合预期。

最佳答案

似乎 xml 部分不在请求的第一行中。

[empty-line]
<?xml version="1.0" encoding="UTF-8" ?>
<multipay>
<project_id>WHITEOUT</project_id>
<amount>24.51</amount>
<currency_code>EUR</currency_code>
<reasons>
<reason>Testueberweisung</reason>
<reason>-TRANSACTION-</reason>
</reasons>
<success_url>http://WHITEOUT?stage=paymentAuthorizationSuccessful</success_url>
<success_link_redirect>1</success_link_redirect>
<abort_url>http://WHITEOUT?stage=paymentCancelled</abort_url>
<su />
</multipay>

尝试删除前导(和尾随)空格。这应该可以解决问题。

关于python - 在 Python 中发布 HTTP : Reserved XML Name. 行 : 2, 字符:40,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28068275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com