1

Hey I am struggling to have a static file available for download using Python and Tornado on my server.

class templateHandler(tornado.web.RequestHandler):
def get(self):
    self.write("""
    <a href="/download"> Download </a>
    """)

application = tornado.web.Application([
(r"/", MyFormHandler),
(r"/results", MyFormHandler),
(r"/multi", MyFileHandler),
(r"/upload",MyFileHandler),
(r'/download',tornado.web.StaticFileHandler,{'path':"L:/Template.csv"}),
(r'/template', templateHandler),
(r"/SFA",SFAHandler),
])

Can someone help me out. I am not 100% certain on how the file handler works. Thanks for your help!

EDIT: Here is the error message:

ERROR:root:Uncaught exception GET /download (10.18.4.160)
HTTPRequest(protocol='http', host='IPadress', method='GET', uri='/download', version='HTTP/1.1', remote_ip='IPaddress', body='', headers={'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', >'Referer': 'IPadress/template', 'Host': 'IPaddress', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0'})
Traceback (most recent call last):
  File "WEB.PY LOCATION", line >988, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
TypeError: get() takes at least 2 arguments (1 given)
ERROR:root:500 GET /download (IPaddress) 0.00ms
Chris
  • 1,416
  • 18
  • 29
Nick Trileski
  • 151
  • 1
  • 2
  • 8
  • what is happening right now? when you go to `/download` in a browser? – dm03514 Jul 15 '13 at 20:12
  • Sorry forgot to include the error message. Edited out some of the IPs and web.py location. Sorry its a crappy format, not sure how to do it other than block formatting. Thanks again. – Nick Trileski Jul 15 '13 at 20:21

1 Answers1

1

I'm thinking it has to do with StaticFileHandler.get expecting a path, usually it does not serve a single file, but instead serves a directory of files, and takes a filename i don't have time to dig into it right now but it sshould be something like

(r'/download/(.*)',tornado.web.StaticFileHandler,{'path':"L:/"}),

now if you go to

/download/Template.csv it should serve it. Sorry I don't have time right now to look into source to confirm

dm03514
  • 54,664
  • 18
  • 108
  • 145
  • WARNING:root:403 GET /download/Template.csv (127.0.0.1): \Template.csv is not in root static directory WARNING:root:403 GET /download/Template.csv (127.0.0.1) 16.00ms >its giving me a 403 forbidden error – Nick Trileski Jul 15 '13 at 20:42
  • great! What are your `L:/` permissions? does the user tornado is running under have read permissions from `L:/`? – dm03514 Jul 15 '13 at 22:03
  • I think I found the problem in that case I think my python distro is installed on a different drive... Will fix and update tomorrow. Thanks! – Nick Trileski Jul 16 '13 at 01:01
  • Ok still trying to fix it but I am not sure where to put this Template so the directory its in is given read access. – Nick Trileski Jul 16 '13 at 13:05
  • @NickTrileski just for testing could you serve files from a subdirectory of your python project? – dm03514 Jul 16 '13 at 13:06
  • Yes. That was what I was trying to do - the template sits in L:\\Project1\\docs while the python file executed is in L:\\Project1 – Nick Trileski Jul 16 '13 at 13:16
  • Ok I got it, i was missing a slash in my static file handler. However its not doing what I want. I want to download the file and save it to my computer. In my case its basically performing a cat Template.csv and displaying it within the browser. – Nick Trileski Jul 16 '13 at 13:36