我在 python 2.5 中有一个应用程序,它通过 suds 0.3.6 发送数据.
I have an application in python 2.5 which sends data through suds 0.3.6.
问题是数据包含非ascii字符,所以我需要soap消息中存在以下标头:
The problem is that the data contains non-ascii characters, so I need the following header to exist in the soap message:
Content-Type="text/html; charset="utf-8"
而 SOAP 消息中存在的标头只是:
and the header that exists in the SOAP message is just:
Content-Type="text/html"
我知道它在 suds 0.4 中已修复,但它需要 Python2.6,我需要 Python2.5,因为我使用 CentOS,它需要那个版本.所以问题是:
I know that it is fixed in suds 0.4, but it requires Python2.6 and I NEED Python2.5 because I use CentOS and it needs that version. So the question is:
如何更改或添加新的 HTTP 标头到 SOAP 消息?
How could I change or add new HTTP headers to a SOAP message?
当你在 urllib2 中创建 opener 时,你可以使用一些处理程序来做任何你想做的事情.例如,如果你想在 suds 中添加一个新的 header,你应该这样做:
When you create the opener in urllib2, you can use some handlers to do whatever you want. For example, if you want to add a new header in suds, you should do something like this:
https = suds.transport.https.HttpTransport()
opener = urllib2.build_opener(HTTPSudsPreprocessor)
https.urlopener = opener
suds.client.Client(URL, transport = https)
HTTPSudsPreprocessor 是您自己的处理程序,它应该如下所示:
where HTTPSudsPreprocessor is your own handler, and it should look like this:
class HTTPSudsPreprocessor(urllib2.BaseHandler):
def http_request(self, req):
req.add_header('Content-Type', 'text/xml; charset=utf-8')
return req
https_request = http_request
您必须覆盖的方法取决于您想要做什么.请参阅 Python.org 中的 urllib2 文档
The methods you have to override depend on what you want to do. See urllib2 documentation in Python.org
这篇关于如何在 suds 0.3.6 中添加 http 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 Python 中将货币字符串转换为浮点数?How do I convert a currency string to a floating point number in Python?(如何在 Python 中将货币字符串转换为浮点数?)
在 Pandas 中解析多索引 Excel 文件Parsing a Multi-Index Excel File in Pandas(在 Pandas 中解析多索引 Excel 文件)
pandas 时间序列 between_datetime 函数?pandas timeseries between_datetime function?( pandas 时间序列 between_datetime 函数?)
pandas 重新采样到每月的特定工作日pandas resample to specific weekday in month( pandas 重新采样到每月的特定工作日)
Python - 如何标准化时间序列数据Python - how to normalize time-series data(Python - 如何标准化时间序列数据)
statsmodels 使用 ARMA 模型进行预测statsmodels forecasting using ARMA model(statsmodels 使用 ARMA 模型进行预测)