How to add http headers in suds 0.3.6?(如何在 suds 0.3.6 中添加 http 标头?)
问题描述
我在 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 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 suds 0.3.6 中添加 http 标头?


- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- python-m http.server 443--使用SSL? 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 沿轴计算直方图 2022-01-01