J
John Gordon
I'm writing some code that queries a Microsoft Exchange Web Services server.
The server is responding with a 411 Length Required error, which is strange
because I am definitely sending a Content-Length header.
Here's the code:
-----------------------------------------------------
import httplib
import base64
SoapMessage = """\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
Traversal="Shallow">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
<t:AdditionalProperties>
<t:FieldURI FieldURI="calendar:Start" />
<t:FieldURI FieldURI="calendar:End" />
<t:FieldURI FieldURI="calendar:LegacyFreeBusyStatus" />
</t:AdditionalProperties>
</ItemShape>
<ParentFolderIds>
<tistinguishedFolderId Id="calendar" />
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>\
"""
host = "some.host.com"
username = "myUsername"
password = "myPassword"
auth = base64.encodestring(username + ":" + password)
conn = httplib.HTTPSConnection(host)
conn.set_debuglevel(5)
conn.putrequest("POST", "/EWS/Exchange.asmx")
conn.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
conn.putheader("Proxy-Authorization", "Basic %s" % auth)
conn.putheader("Content-Length", "%d" % len(SoapMessage))
conn.putheader("User-Agent", "Python post")
conn.endheaders()
conn.send(SoapMessage)
resp = conn.getresponse()
body = resp.read()
headers = resp.msg
version = resp.version
status = resp.status
reason = resp.reason
conn.close()
print "Response: ", status, reason
print "Headers: ", headers
print body
-----------------------------------------------------
As you can see, I am including the call to putheader() for Content-Length,
and the debugging output confirms that the header is present in the outgoing
message.
So why am I getting a 411 Length Required error?
The server is responding with a 411 Length Required error, which is strange
because I am definitely sending a Content-Length header.
Here's the code:
-----------------------------------------------------
import httplib
import base64
SoapMessage = """\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
Traversal="Shallow">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
<t:AdditionalProperties>
<t:FieldURI FieldURI="calendar:Start" />
<t:FieldURI FieldURI="calendar:End" />
<t:FieldURI FieldURI="calendar:LegacyFreeBusyStatus" />
</t:AdditionalProperties>
</ItemShape>
<ParentFolderIds>
<tistinguishedFolderId Id="calendar" />
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>\
"""
host = "some.host.com"
username = "myUsername"
password = "myPassword"
auth = base64.encodestring(username + ":" + password)
conn = httplib.HTTPSConnection(host)
conn.set_debuglevel(5)
conn.putrequest("POST", "/EWS/Exchange.asmx")
conn.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
conn.putheader("Proxy-Authorization", "Basic %s" % auth)
conn.putheader("Content-Length", "%d" % len(SoapMessage))
conn.putheader("User-Agent", "Python post")
conn.endheaders()
conn.send(SoapMessage)
resp = conn.getresponse()
body = resp.read()
headers = resp.msg
version = resp.version
status = resp.status
reason = resp.reason
conn.close()
print "Response: ", status, reason
print "Headers: ", headers
print body
-----------------------------------------------------
As you can see, I am including the call to putheader() for Content-Length,
and the debugging output confirms that the header is present in the outgoing
message.
So why am I getting a 411 Length Required error?