473,503 Members | 6,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple socket code

**** Post for FREE via your newsreader at post.usenet.com ****
Please help me to put some content on apache + DAV server, whas wrong?

Expand|Select|Wrap|Line Numbers
  1.  
  2. import socket, os, stat
  3.  
  4. file=open('/home/nikola/somefile','rb')
  5. lenght=os.fstat(file.fileno())[stat.ST_SIZE]
  6. print lenght
  7.  
  8. headers={}
  9. headers['Host']='localhost'
  10. headers['Authorization']='Basic bmlrb2xhOnRlc3Q='
  11. headers['Accept-Encoding']='identity'
  12. headers['Content-Type']='application/octet-stream'
  13. headers['Content-Encoding']='None'
  14. headers['Content-Lenght']=lenght
  15.  
  16.  
  17. data = '%s %s %s\r\n' %('PUT', '/dav/test1','HTTP/1.1')
  18. for header, value in headers.items():
  19. data += '%s: %s\r\n'%(header,value)
  20.  
  21. data += '\r\n'
  22.  
  23. sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24. sock.connect(('localhost', 80))
  25. sock.send(data)
  26. sock.send(file.read()) #doesnt work why?
  27. response=sock.recv(2000)
  28. print response
  29. sock.close()
  30.  
  31.  


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jul 18 '05 #1
3 1403
Nikola Bjelicic wrote:
**** Post for FREE via your newsreader at post.usenet.com ****
Please help me to put some content on apache + DAV server, whas wrong?

Expand|Select|Wrap|Line Numbers
  1. import socket, os, stat
  2. file=open('/home/nikola/somefile','rb')
  3. lenght=os.fstat(file.fileno())[stat.ST_SIZE]
  4. print lenght
  5. headers={}
  6. headers['Host']='localhost'
  7. headers['Authorization']='Basic bmlrb2xhOnRlc3Q='
  8. headers['Accept-Encoding']='identity'
  9. headers['Content-Type']='application/octet-stream'
  10. headers['Content-Encoding']='None'
  11. headers['Content-Lenght']=lenght
  12. data = '%s %s %s\r\n' %('PUT', '/dav/test1','HTTP/1.1')
  13. for header, value in headers.items():
  14.   data += '%s: %s\r\n'%(header,value)
  15. data += '\r\n'
  16. sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  17. sock.connect(('localhost', 80))
  18. sock.send(data)
  19. sock.send(file.read()) #doesnt work why?
  20. response=sock.recv(2000)
  21. print response
  22. 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/li...-examples.html

Jeremy Jones
Jul 18 '05 #2
**** Post for FREE via your newsreader at post.usenet.com ****

Jeremy Jones wrote:

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

http://www.python.org/doc/current/li...-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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jul 18 '05 #3
> 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
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9012
by: Johannes Eble | last post by:
Hello Python community, I am trying the echo-client and echo-server examples in Chapter 10, "Programming Python" by Mark Lutz. It is probably the most simple sockets sample: A socket server just...
0
1349
by: zoran | last post by:
Hi, I have a simple TCP server client in .net and for some reason the Accept() function in the Server part never gets called and never returns a new socket. This thing has been driving me nuts for...
1
1752
by: jm | last post by:
Easy probably, please read on. I know some of you have commented already about some of my socket question. I appreciate that. I have a Form1: static void Main() { Application.Run(new...
0
3198
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports...
1
1877
by: Josema | last post by:
Hi, Im newbie in Sockets, and im trying to make an application to listen from a port, and another to send bytes to this port... I'm using asyncronous sockets, and i have the most of the code...
2
5170
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
4
3242
by: SpreadTooThin | last post by:
client: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("192.168.1.101", 8080)) print 'Connected' s.send('ABCD') buffer = s.recv(4) print buffer s.send('exit')
0
1558
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the...
2
5395
by: fredszky | last post by:
Hello I am very new to perl, however i managed to make this server/client work with udp, now i would like to do the same thing but with TCP/IP, what must i do? Server: #!perl -w # Server...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.