Merge pull request #625 from coditamar/browse_scrape_text_tests_and_fix

scrape_text: (1) added tests , (2) handle RequestException
This commit is contained in:
Toran Bruce Richards
2023-04-10 07:56:04 +01:00
committed by GitHub
2 changed files with 107 additions and 1 deletions

View File

@@ -6,7 +6,14 @@ from llm_utils import create_chat_completion
cfg = Config()
def scrape_text(url):
response = requests.get(url, headers=cfg.user_agent_header)
# Most basic check if the URL is valid:
if not url.startswith('http'):
return "Error: Invalid URL"
try:
response = requests.get(url, headers=cfg.user_agent_header)
except requests.exceptions.RequestException as e:
return "Error: " + str(e)
# Check if the response contains an HTTP error
if response.status_code >= 400: