Doc2txtLoader not working for web paths
Labels: name: area: doc loader, name: auto:bug

### System Info

Windows 11, Langchain 0.0327, Python 3.10.

The Doc2txtLoader does not work for web paths, as a PermissionError occurs  when self.tempfile attempts to write content to the tempfile:


        if not os.path.isfile(self.file_path) and self._is_valid_url(self.file_path):
            r = requests.get(self.file_path)

            if r.status_code != 200:
                raise ValueError(
                    "Check the url of your file; returned status code %s"
                    % r.status_code
                )

            self.web_path = self.file_path
            self.temp_file = tempfile.NamedTemporaryFile()
            **self.temp_file.write(r.content)**
            self.file_path = self.temp_file.name
        elif not os.path.isfile(self.file_path):
            raise ValueError("File path %s is not a valid file or url" % self.file_path)

It produces a Permission Error: _[Errno 13] Permission denied:_ as the file is already open, and will be deleted on close.

I can work around this by replacing this section of the code with the following:

        if not os.path.isfile(self.file_path) and self._is_valid_url(self.file_path):
            self.temp_dir = tempfile.TemporaryDirectory()
            _, suffix = os.path.splitext(self.file_path)
            temp_pdf = os.path.join(self.temp_dir.name, f"tmp{suffix}")
            self.web_path = self.file_path
            if not self._is_s3_url(self.file_path):
                r = requests.get(self.file_path, headers=self.headers)
                if r.status_code != 200:
                    raise ValueError(
                        "Check the url of your file; returned status code %s"
                        % r.status_code
                    )

                with open(temp_pdf, mode="wb") as f:
                    f.write(r.content)
                self.file_path = str(temp_pdf)
        elif not os.path.isfile(self.file_path):
            raise ValueError("File path %s is not a valid file or url" % self.file_path)

This is the method that works for the PDF loader. 

The workaround is fine for now but will cause a problem if I need to update the langchain version any time in the future.


### Who can help?

@hwchase17 @eyurtsev 

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [X] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

from langchain.document_loaders import Docx2txtLoader
loader = Docx2txtLoader("https://file-examples.com/wp-content/storage/2017/02/file-sample_100kB.docx")
doc = loader.load()[0]


Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 3, in <module>
  File "C:\Users\crawleyb\PycharmProjects\SharepointGPT\venv\lib\site-packages\langchain\document_loaders\word_document.py", line 55, in load
    return [
  File "C:\Users\crawleyb\PycharmProjects\SharepointGPT\venv\lib\site-packages\docx2txt\docx2txt.py", line 76, in process
    zipf = zipfile.ZipFile(docx)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1251, in __init__
    self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\

### Expected behavior

The DocumentLoader should be able to get the contents of the docx file, loader.load()[0] should return a Document object.