xtekky/gpt4free · error · ValueError

url must start with http:// or https://

Error message

url must start with http:// or https://

What it means

Thrown by MarkItDown.convert_url() when the url string does not start with http:// or https://. Only these two schemes are supported because the converter fetches over HTTP; ftp://, file://, mailto:, chrome-extension:// and bare hostnames are rejected.

Source

Thrown at g4f/integration/markitdown/__init__.py:239

            owner, repo, ref, path = (m.group(1), m.group(2), m.group(3), m.group(4))
            # Strip a trailing slash if any
            path = path.rstrip("/")
            return f"https://raw.githubusercontent.com/{owner}/{repo}/{ref}/{path}"

        # Tree (directory) URLs and repo roots: cannot map to a single raw file
        return url

    def convert_url(
        self,
        url: str,
        *,
        stream_info: Optional[StreamInfo] = None,
        **kwargs: Any,
    ) -> DocumentConverterResult:
        if url is None or not isinstance(url, str) or url.strip() == "":
            raise ValueError("url must be a non-empty string")
        if not url.startswith(("http://", "https://")):
            raise ValueError("url must start with http:// or https://")
        if url.startswith("https://github.com/"):
            # Special case for GitHub URLs -- convert to raw content URL
            url = self._convert_github_url_to_raw(url)
        return super().convert_url(url, stream_info=stream_info, **kwargs)

View on GitHub (pinned to 973504e177)

Solutions

  1. Normalize the scheme first: if url.startswith('//'): url = 'https:' + url elif '://' not in url: url = 'https://' + url.
  2. For local files use md.convert(path) / convert_stream(), not convert_url().
  3. Drop or rewrite unsupported-scheme links earlier in your scraping pipeline.

Example fix

// before
result = md.convert_url("example.com/docs/page")

// after
url = "example.com/docs/page"
if not url.startswith(("http://", "https://")):
    url = "https://" + url
result = md.convert_url(url)
Defensive patterns

Strategy: validation

Validate before calling

def http_url(url: str) -> bool:
    return isinstance(url, str) and url.startswith(("http://", "https://"))

def normalize(url: str) -> str:
    if url.startswith("//"):
        return "https:" + url
    if "://" not in url:
        return "https://" + url
    return url

Prevention

When it happens

Trigger: convert_url('ftp://example.com/doc.pdf'); convert_url('file:///tmp/a.html'); convert_url('example.com/page') (missing scheme); a URL stored without scheme in a database.

Common situations: User input like 'www.site.com/x' copied without the scheme; file:// URLs from browser drag-and-drop or local HTML that should be passed to convert() instead; scheme-relative URLs ('//cdn.site.com/a') from scraped HTML.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/33838bf2994cfc37. Report an issue: GitHub.