You are not logged in.

#1 2010-11-04 05:20:14

N-Acc
Member
Registered: 2009-02-19
Posts: 18

[solved] python SocketServer serving large files

I am trying to get a quick http server so that I can use it to easily share files to friends now and then. However all scripts I can find do not work ... python2 keeps complaining (I am using 2.7-3 on x64)...

I tried woof, Xyne's quickserve script on AUR, or even `python2 -m SimpleHTTPServer', the Traceback is exactly the same:

~>$ woof ~/downloads/ubuntu-10.04.1-desktop-amd64.iso 
Now serving on http://192.168.1.167:8080/
localhost.localdomain - - [04/Nov/2010 01:08:10] "GET /ubuntu-10.04.1-desktop-amd64.iso HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52448)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 641, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 301, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

This happens when I try to serve files that are several megabyte large, however for small files of KB size everything works okay.

So is there something I am missing or it's a python problem? And are there any good ad hoc http servers floating around?

[edit: grammar]

Last edited by N-Acc (2010-11-04 18:24:10)

Offline

#2 2010-11-04 16:47:32

awkwood
Member
From: .au <=> .ca
Registered: 2009-04-23
Posts: 91

Re: [solved] python SocketServer serving large files

You could try the following to see if Ruby does the same thing for large files.

First, install the thin gem like so:

gem install thin

Add a rackup file to the directory you'd like to serve, I've called mine config.ru

# config.ru
run Rack::Directory.new(Dir.pwd)

Then you can start the server using the "thin" command:

thin -Rconfig.ru start

The files will be hosted on port 3000 by default, use the "-p" switch to specify which port thin should use.

Offline

#3 2010-11-04 18:23:52

N-Acc
Member
Registered: 2009-02-19
Posts: 18

Re: [solved] python SocketServer serving large files

Thanks a lot awkwood, thin is working fine here. I will go with ruby then -

Offline

#4 2010-11-04 21:14:11

hexanol
Member
From: Canaduh
Registered: 2009-08-04
Posts: 95

Re: [solved] python SocketServer serving large files

I know this thread has been tagged as solved, but I'll give 2 others alternative to set up a quick HTTP server with python:

With python 3.x:

$ python -m http.server

Or with if you have twisted installed (pacman -S twisted):

$ twistd -d web --path=.

The -n option is for 'nodaemon'.

Offline

Board footer

Powered by FluxBB