Python 2.7 python中的POST SOAP请求获取错误响应:403禁止
请问有人能帮忙吗?我试图在python中发布SOAP请求,但得到错误响应403:禁止。我的代码如下所示: 我正在使用python导入:Python 2.7 python中的POST SOAP请求获取错误响应:403禁止,python-2.7,Python 2.7,请问有人能帮忙吗?我试图在python中发布SOAP请求,但得到错误响应403:禁止。我的代码如下所示: 我正在使用python导入: import httplib import base64 import string #the message message = """<soap:Envelope ...rest message </soap:Envelope>""" host = "host.test.com" url = 'h
import httplib
import base64
import string
#the message
message = """<soap:Envelope ...rest message </soap:Envelope>"""
host = "host.test.com"
url = 'https://server.etc.com' #End point url
在这里,我尝试构建标题:
webservice.putrequest("POST", url)
webservice.putheader("Host", host)
webservice.putheader("User-Agent", "Python http auth")
webservice.putheader("Content-Type:", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(message))
webservice.putheader("SOAPAction",webSoapAction)
webservice.putheader('Authorization', auth)
webservice.endheaders()
webservice.send(message)
我应该在这里得到答复
#get the response
statuscode, statusmessage, header = webservice.getreply()
print "Response: ", statuscode, statusmessage
print "Headers: ",header
res = webservice.getfile().read()
print 'Content: ', res
关于基本的auth头构造,有两件事:
- 在“基本”和“秘密”之间留出一个空格
- 在用户名和密码之间使用“:”而不是“.”
#the Authentication in base64 encoding form for Basic Authentication
auth = 'Basic ' + string.strip(base64.encodestring(username +':'+ password))
谢谢你,雷克斯。我不知道这是否与使用http(主机)或httpconnection(主机)有关。webservice=httplib.HTTP(主机)webservice=httplib.HTTPConnection(主机,80)
#the Authentication in base64 encoding form for Basic Authentication
auth = 'Basic ' + string.strip(base64.encodestring(username +':'+ password))