1

I new in web.py, and I try to create a download command.

I create this one:

import web

urls = (
    '/', 'index',
    '/download', 'Download'
)

class index:
    def GET(self):
        return "Hello, world!"

class Download:
    def GET(self):
           path = 'http:\\localhost:8080\C:\11\229077_6482396906_558_n.jpg' 
           web.header('Content-Disposition', 'attachment; filename="fname.ext"')
           web.header('Content-type','images/jpeg')
           web.header('Content-transfer-encoding','binary') 
           return open(path, 'rb').read()

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

and I have two main problems:

  1. When I enter to http://localhost:8080/download, it gives me 500 internal Server Error. Why?

  2. I cant choose which file I would like to download (just change the path argument manually). How I give to this function external argument?

Or Smith
  • 3,556
  • 13
  • 42
  • 69

2 Answers2

0
  1. 500 is the generic error code, so it's hard to diagnose. While setting up your code, I'd check your URIs in the browser to determine if your server is running correctly. Full list of error codes - link.

  2. You can only find files that have links pointing to them. See, for example, these wget commands.

Community
  • 1
  • 1
philshem
  • 24,761
  • 8
  • 61
  • 127
0

2.For example add this to your code:

filename = web.input().file

So it would return the desired filename when entering the link:

yoursite.tld/downloads?file=FILENAME

Read more on this topic here: http://webpy.org/cookbook/input

yrk
  • 155
  • 1
  • 3
  • 17