Чек, тут у тебя проблема с POST-запросом по-моему, он по-другому должен выглядеть. У меня реализовано так:
def send_queries(self, mainid, query_list):
self.__query_list = query_list
file = self.__make_xml(mainid, query_list)
content_type, body = self.__encode_queries(file)
connection = httplib.HTTP(self.__host)
connection.putrequest('POST', self.__script)
connection.putheader('Content-Type', content_type)
connection.putheader('Content-Length', str(len(body)))
connection.endheaders()
connection.send(body)
errcode, errmsg, headers = connection.getreply()
response = connection.file.read()
response = response.decode('cp1251') # Декодируем из win-кодировки
response = response.replace('windows-1251', 'utf-8', 1) # Меняем заголовок
tmp = open('tmp.xml', 'w')
tmp.write(response)
tmp.close
if not response.find('') == -1:
raise ServerUnavailableException()
return self.__make_response_list(response)
def __encode_queries(self, file):
BOUNDARY = '----------'+str(random.randint(100000000, 999999999))
CRLF = '\r\n'
L = []
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (file[0], file[1]))
L.append('Content-Type: text/xml')
L.append('')
L.append(file[2].encode("utf-8"))
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body