Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

open file in python network url

from requests_testadapter import Resp

class LocalFileAdapter(requests.adapters.HTTPAdapter):
    def build_response_from_file(self, request):
        file_path = request.url[7:]
        with open(file_path, 'rb') as file:
            buff = bytearray(os.path.getsize(file_path))
            file.readinto(buff)
            resp = Resp(buff)
            r = self.build_response(request, resp)

            return r

    def send(self, request, stream=False, timeout=None,
             verify=True, cert=None, proxies=None):

        return self.build_response_from_file(request)

requests_session = requests.session()
requests_session.mount('file://', LocalFileAdapter())
requests_session.get('file://<some_local_path>')
Comment

PREVIOUS NEXT
Code Example
Python :: python regex (d)(?=d1) 
Python :: recurrent neural network pytorch 
Python :: python table code 
Python :: how to count all files on linux 
Python :: python basic programs 
Python :: lower method in python 
Python :: Implement a binary search of a sorted array of integers Using pseudo-code. 
Python :: How to check the number of occurence of each character of a given string in python 
Python :: pandas use dict to transform entries 
Python :: discord py server.channels 
Python :: pd.cut in pandas 
Python :: python power of e 
Python :: python all() function 
Python :: python re.split() 
Python :: full_like numpy 
Python :: Percent to number python 
Python :: Python NumPy delete Function Example Deletion from 1D array 
Python :: when iterating through a pandas dataframe using index, is the index +1 able to be compared 
Python :: for loop in python 
Python :: pairs with specific difference 
Python :: Program to Compute LCM Using GCD 
Python :: convert mixed number string to float 
Python :: start virtualenv with python version 
Python :: how to use the sleep function in python 
Python :: handling exceptions 
Python :: how to find ascii value by python 
Python :: login views django template passing 
Python :: self keyword in python 
Python :: deque python 
Python :: dot product of lists python 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =