I am following this Virtuoso Web Service example. My the response from a POST has a non-zero .length, but .read() is empty. This only happens when POST is successful. If I intentionally make a mistake I will get a non-zero .read().
import httplib
url = 'lod.openlinksw.com'
xmlString = '''<?xml version="1.0"?>
<query xmlns="http://openlinksw.com/services/facets/1.0" inference="" same-as="">
<text>Seattle Mariners traveled all the way to Japan to watch</text>
<view type="text" limit="20" offset=""/>
</query>'''
xml = open('a.xml','w')
xml.write(xmlString)
xml.close()
xml = open('a.xml')
headers = {'Content-Type': 'text/xml',}
conn = httplib.HTTPConnection(url)
conn.request("POST", "/fct/service", xml, headers)
re = conn.getresponse()
conn.close()
data = re.read()
print re.reason, re.status, '| len:', re.length, '| read() len:', len(data)
Return…
OK 200 | len: 19902 | read() len: 0
If you intentionally malform the XML (e.g. “query” >> “queryzzz”)…
Internal Server Error 500 | len: 0 | read() len: 340
I am sure I am just doing something silly. Where’s my 19902 byte response?
Change
to
You need to read the data before closing the connection or any not yet transferred bytes will be lost.