simple socket code

Nikola Bjelicic nikola at bonbon.net
Thu Sep 30 18:53:30 CEST 2004


**** Post for FREE via your newsreader at post.usenet.com ****


Please help me to put some content on apache + DAV server, whas wrong?

[code]

import socket, os, stat

file=open('/home/nikola/somefile','rb')
lenght=os.fstat(file.fileno())[stat.ST_SIZE]
print lenght

headers={}
headers['Host']='localhost'
headers['Authorization']='Basic bmlrb2xhOnRlc3Q='
headers['Accept-Encoding']='identity'
headers['Content-Type']='application/octet-stream'
headers['Content-Encoding']='None'
headers['Content-Lenght']=lenght


data = '%s %s %s\r\n' %('PUT', '/dav/test1','HTTP/1.1')
for header, value in headers.items():
  data += '%s: %s\r\n'%(header,value)

data += '\r\n'

sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 80))
sock.send(data)
sock.send(file.read()) #doesnt work why?
response=sock.recv(2000)
print response
sock.close()

[/code]



-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 *** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
                      http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



More information about the Python-list mailing list