Transport adapter for fetching file:// URLs with the requests python library
Python
Latest commit 83035a4 Oct 13, 2016 @dashea New version 1.4.1
The only change is to add a wheel distribution.
Permalink
Failed to load latest commit information.
tests Handle files with a drive component. Aug 24, 2015
.gitignore Initial commit Mar 10, 2015
CHANGES.rst New version 1.4.1 Oct 13, 2016
LICENSE Initial commit Mar 10, 2015
MANIFEST.in
README.rst Fix spelling. Mar 10, 2015
python-requests-file.spec Switch to the new Fedora packaging guidelines. Sep 14, 2015
requests_file.py Handle files with a drive component. Aug 24, 2015
requirements.txt Initial commit Mar 10, 2015
setup.cfg Release as a universal wheel Oct 13, 2016
setup.py New version 1.4.1 Oct 13, 2016

README.rst

Requests-File

Requests-File is a transport adapter for use with the Requests Python library to allow local filesystem access via file:// URLs.

To use:

import requests
from requests_file import FileAdapter

s = requests.Session()
s.mount('file://', FileAdapter())

resp = s.get('file:///path/to/file')

Features

  • Will open and read local files
  • Might set a Content-Length header
  • That's about it

No encoding information is set in the response object, so be careful using Response.text: the chardet library will be used to convert the file to a unicode type and it may not detect what you actually want.

EACCES is converted to a 403 status code, and ENOENT is converted to a 404. All other IOError types are converted to a 400.

Contributing

Contributions welcome! Feel free to open a pull request against https://github.com/dashea/requests-file

License

To maximise compatibility with Requests, this code is licensed under the Apache license. See LICENSE for more details.