473,569 Members | 2,764 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 1409
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
9017
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 echoing the socket clients' requests. The program works so far. I first start the server in one dos box, then the client in another dos box on...
0
1355
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 days, here is the code please help if you can (the two machines that I am trying to connect are on a LAN Ethernet): Client() { Socket...
1
1757
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 Form1()); clsListening.AsynchronousSocketListener.StartListening();
0
3202
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 System.Net
1
1890
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 done, but i dont know doesnt work. //******************************************* //here the server application
2
5174
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 sends the message "Ping" to the server, which reads it and answers with a "Pong". The game is really simple and the coding should be also very simple!...
4
3247
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
1564
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 socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the...
2
5399
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 Program use IO::Socket::INET; print ">> Server Program <<\n";
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
933
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.