Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Retry url encode fix (#2136)
Shuchang Zheng80cdc1e0e22e
diff --git a/skyvern/forge/sdk/api/files.py b/skyvern/forge/sdk/api/files.pyindex ea5c61de6..91b5abbc0 100644--- a/skyvern/forge/sdk/api/files.py+++ b/skyvern/forge/sdk/api/files.py@@ -12,11 +12,13 @@ from urllib.parse import unquote, urlparseimport aiohttpimport structlogfrom multidict import CIMultiDictProxy+from yarl import URLfrom skyvern.config import settingsfrom skyvern.constants import BROWSER_DOWNLOAD_TIMEOUT, BROWSER_DOWNLOADING_SUFFIX, REPO_ROOT_DIRfrom skyvern.exceptions import DownloadFileMaxSizeExceeded, DownloadFileMaxWaitingTimefrom skyvern.forge.sdk.api.aws import AsyncAWSClient+from skyvern.utils.url_validators import encode_urlLOG = structlog.get_logger()@@ -83,7 +85,8 @@ async def download_file(url: str, max_size_mb: int | None = None) -> str:async with aiohttp.ClientSession(raise_for_status=True) as session:LOG.info("Starting to download file", url=url)- async with session.get(url) as response:+ encoded_url = encode_url(url)+ async with session.get(URL(encoded_url, encoded=True)) as response:# Check the content length if availableif max_size_mb and response.content_length and response.content_length > max_size_mb * 1024 * 1024:# todo: move to root exception.pydiff --git a/skyvern/utils/url_validators.py b/skyvern/utils/url_validators.pyindex 2882ddb92..8100ac054 100644--- a/skyvern/utils/url_validators.py+++ b/skyvern/utils/url_validators.py@@ -1,5 +1,5 @@import ipaddress-from urllib.parse import urlparse+from urllib.parse import quote, urlparse, urlsplit, urlunsplitfrom fastapi import statusfrom pydantic import HttpUrl, ValidationError@@ -59,3 +59,10 @@ def validate_url(url: str) -> str | None:if blocked:raise BlockedHost(host=host)return str(v)+++def encode_url(url: str) -> str:+ parts = list(urlsplit(url))+ # Encode the path while preserving "/" and "%"+ parts[2] = quote(parts[2], safe="/%")+ return urlunsplit(parts)