How to fix Python requests MissingSchema error?

by scrapecrow Dec 19, 2022

MissingSchema error can be seen when using Python requests module to scrape invalid URLs without protocol indicator (the http:// bit).

This usually happens when we accidently supply the scraper with relative URLs instead of absolute URLs:

import requests

requests.get("/product/25")  # default redirect limit is 30
# will raise:
# MissingSchema: Invalid URL '/product/10': No scheme supplied. Perhaps you meant http:///product/10?

When web scraping, it's best to always ensure the scraped URLs are absolute using the urljoin() function:

from urllib.parse import urljoin
import requests

response = requests.get("http://example.com")
urls = [  # lets assume we got this batch of product urls:
    "/product/1",
    "/product/2",
    "/product/3",
]

for relative_url in urls:
    absolute_url = urljoin(response.url, relative_url)
    # this will result in: http://example.com/product/1
    item_response = requests.get(absolute_url)

Related Articles

Guide to Python requests POST method

Discover how to use Python's requests library for POST requests, including JSON, form data, and file uploads, along with response handling tips.

PYTHON
REQUESTS
HTTP
Guide to Python requests POST method

Guide to Python Requests Headers

Our guide to request headers for Python requests library. How to configure and what do they mean.

PYTHON
REQUESTS
HTTP
Guide to Python Requests Headers

How to Scrape YouTube in 2025

Learn how to scrape YouTube, channel, video, and comment data using Python directly in JSON.

SCRAPEGUIDE
PYTHON
HIDDEN-API
How to Scrape YouTube in 2025

Guide to List Crawling: Everything You Need to Know

In-depth look at list crawling - how to extract valuable data from list-formatted content like tables, listicles and paginated pages.

CRAWLING
BEAUTIFULSOUP
PYTHON
Guide to List Crawling: Everything You Need to Know

How to Find All URLs on a Domain

Learn how to efficiently find all URLs on a domain using Python and web crawling. Guide on how to crawl entire domain to collect all website data

CRAWLING
PYTHON
How to Find All URLs on a Domain

How to Capture and Convert a Screenshot to PDF

Quick guide on how to effectively capture web screenshots as PDF documents

SCREENSHOTS
PYTHON
NODEJS
How to Capture and Convert a Screenshot to PDF