python - How do you open and transfer a file on the filesystem in mod_python? -
I'm new to mod_python and Apache, and I'm having trouble returning a file to a user after the GET request.
I've got a very simple setup right now, and was just hoping to open the file and write it for the response:
mod_python imported from the Apache deaf handler (request): req. Content_type = 'application / octet-stream' fIn = open ('response.bin', 'rb') req.write (fIn.read ()) fIn.close () return apache.OK However, I am getting errors while using Open (), and saying that the file does not exist (even if I have checked it a dozen times more often).
- Finding the right files () why not?
Li> What is the best way to return files from the file system? (I will say to make sure that I do not have any better way of using mod_python to return a file.)
thanks
Edit: After finding this thread: I found out that open () works for me if I take the file out of the house to another directory (I was coming out of / home / myname / httpdocs, but if I Data / use it works) why any thoughts work Is received?
Edit 2: Part of my debug error as a request:
MOD_PYTHON error process IC: 13642 Interpreter: '127.0.1.1' Server name: '127.0.1.1 'DocumentRoot:' / var / www 'URI:' /test/mptest.py 'location: any directory:' / home / myname / httpdocs / 'filename:' /home/myname/httpdocs/mptest.py 'PathInfo: '' Step: 'Python Handler' Handler: 'Emptist' traceback (most recent call final): file "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, handler default defaults In = Default_handler, arg = req, silent = hlist.silent) file "/ usr / lib / python2 .5 / site-packages / mod_python / importer.py ", line 1229, _process_target result = _execute_target (config, req, object, arg) file" /usr/lib/python2.5/site-packages/mod_python/importer.py ", Line 1128, _execute_target result =" /home/myname/httpdocs/mptest.py "in line = object (arg), line 13, FIN = open in handler ('/ home / miman e / hd docs / file / response. IanError: [Aron 2] There is no such file or directory: '/home/myname/httpdocs/files/response.bin'
To debug this kind of thing, you can run the mod The _python example requires gathering all the information.
Stop messing with "Doing a dozen times check [exists]" Some assumptions are not correct.
Do something like this to get some debugging information.
DIP handler (request): req.content_type = 'text / plain' request .write (os.environ) req.write (os.getcwd ()) # Return Apache. OK Edit
Now you have a glimpse of important content in this case This may be permissible - you must use os.filestat to make sure. Apache runs mod_python as a user which is almost no useful permission. Apache does not like links, either, but this will not affect mod_python if your file does not have read-to-everything and not in the correct directory, then you will have problems.
You may want to switch over.
Comments
Post a Comment