python / python/cpython

`urlparse` ignores the `scheme` parameter when parsing a URL

Open
#122,565 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

urlparse ignores the scheme parameter when determining what part of a URL is the path and hostname.

from urllib.parse import urlparse
# This should be parsed as: http://www.example.com
parsed_url = urlparse('www.example.com', scheme='http')
print(parsed_url)
print(parsed_url.hostname)

ParseResult(scheme='http', netloc='', path='www.example.com', params='', query='', fragment='')
[empty string]

Should return:

ParseResult(scheme='http', netloc='', path='', params='', query='', fragment='')
www.example.com

Per the docs:

The scheme argument gives the default addressing scheme, to be used only if the URL does not specify one.

CPython versions tested on:

3.8, 3.11

Operating systems tested on:

Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported urlparse behavior on a supported CPython version and inspect the urllib.parse implementation and existing URL-parsing tests. Compare the handling of the scheme argument with the documented behavior and determine whether the requested hostname parsing is compatible with URL syntax. Done means the agreed behavior is covered by regression tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.