shaare.it

ValueError: Invalid URL scheme

7 Dec 2025

1 min read

ValueError: Invalid URL scheme

$ python -c "import requests; requests.get('ftp://example.com')"
Traceback (most recent call last):
  ...
requests.exceptions.InvalidSchema: No connection adapters were found for 'ftp://example.com'

Why this happens

Requests supports HTTP/HTTPS. Using unsupported schemes like ftp, file, or mailto raises schema/adapter errors.

Fix

  • Use a library that supports the scheme (e.g., ftplib for FTP).
  • Or access an HTTP endpoint instead.

Wrong code

import requests
requests.get("file:///etc/hosts")

Fixed code

# Use the right library for the scheme
from ftplib import FTP
ftp = FTP("ftp.example.com")
ftp.login()
# Or switch to https API
# import requests; requests.get("https://api.example.com")