mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Swapping out the tika and replaces requests with httpx
This commit is contained in:
		| @@ -4,7 +4,7 @@ from html import escape | ||||
| from io import BytesIO | ||||
| from io import StringIO | ||||
|  | ||||
| import requests | ||||
| import httpx | ||||
| from bleach import clean | ||||
| from bleach import linkify | ||||
| from django.conf import settings | ||||
| @@ -185,7 +185,7 @@ class MailDocumentParser(DocumentParser): | ||||
|             files[name] = (name, BytesIO(content)) | ||||
|         headers = {} | ||||
|         try: | ||||
|             response = requests.post(url_merge, files=files, headers=headers) | ||||
|             response = httpx.post(url_merge, files=files, headers=headers) | ||||
|             response.raise_for_status()  # ensure we notice bad responses | ||||
|         except Exception as err: | ||||
|             raise ParseError(f"Error while converting document to PDF: {err}") from err | ||||
| @@ -280,7 +280,7 @@ class MailDocumentParser(DocumentParser): | ||||
|                 data["pdfFormat"] = "PDF/A-3b" | ||||
|  | ||||
|             try: | ||||
|                 response = requests.post( | ||||
|                 response = httpx.post( | ||||
|                     url, | ||||
|                     files=files, | ||||
|                     headers=headers, | ||||
| @@ -336,7 +336,7 @@ class MailDocumentParser(DocumentParser): | ||||
|             "scale": "1.0", | ||||
|         } | ||||
|         try: | ||||
|             response = requests.post( | ||||
|             response = httpx.post( | ||||
|                 url, | ||||
|                 files=files, | ||||
|                 headers=headers, | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import os | ||||
| from pathlib import Path | ||||
|  | ||||
| import dateutil.parser | ||||
| import requests | ||||
| import httpx | ||||
| from django.conf import settings | ||||
| from tika import parser | ||||
|  | ||||
| @@ -106,7 +106,7 @@ class TikaDocumentParser(DocumentParser): | ||||
|                 data["pdfFormat"] = "PDF/A-3b" | ||||
|  | ||||
|             try: | ||||
|                 response = requests.post(url, files=files, headers=headers, data=data) | ||||
|                 response = httpx.post(url, files=files, headers=headers, data=data) | ||||
|                 response.raise_for_status()  # ensure we notice bad responses | ||||
|             except Exception as err: | ||||
|                 raise ParseError( | ||||
|   | ||||
							
								
								
									
										11
									
								
								src/paperless_tika/tests/utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/paperless_tika/tests/utils.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| import pytest | ||||
| from pytest_httpx import HTTPXMock | ||||
|  | ||||
|  | ||||
| class HttpxMockMixin: | ||||
|     @pytest.fixture(autouse=True) | ||||
|     def httpx_mock_auto(self, httpx_mock: HTTPXMock): | ||||
|         """ | ||||
|         Workaround for allowing use of a fixture with unittest style testing | ||||
|         """ | ||||
|         self.httpx_mock = httpx_mock | ||||
		Reference in New Issue
	
	Block a user
	 Trenton H
					Trenton H