simple socket code

N

Nikola Bjelicic

**** 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()



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

Jeremy Jones

Nikola said:
**** 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()



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

Do you _really_ want to do this by hand with sockets? I would recommend
trying httplib:

http://www.python.org/doc/current/lib/httplib-examples.html

Jeremy Jones
 
N

Nikola Bjelicic

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

Jeremy said:
Do you _really_ want to do this by hand with sockets? I would recommend
trying httplib:

http://www.python.org/doc/current/lib/httplib-examples.html

Jeremy Jones

I would really like to post file-like object which is presumably large. I
need this for connection tracking like with urlgrabber, but for POST and
PUT requests.

Nikola Bjelicic

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

Josiah Carlson

lenght=os.fstat(file.fileno())[stat.ST_SIZE]
print lenght
headers['Content-Lenght']=lenght

I am not experienced with webDav, but perhaps you are trying to spell
"length". I believe the name of the header matters in this case.

- Josiah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,351
Latest member
RoxiePulli

Latest Threads

Top