Python Glossary Русский

all Python 3until 3.14Removed from the standard libraryterm

urllib.request.FancyURLopener

removed

An extended URLopener with redirects and a custom User-Agent. Removed in Python 3.14 — use build_opener() and urlopen().

Syntax

class MyOpener(urllib.request.FancyURLopener): ...  # до 3.14

FancyURLopener added redirect following and simple authentication on top of URLopener; to change the User-Agent you subclassed it and overrode the version attribute. It was removed along with URLopener as an outdated Python 2 interface that no longer got fixes. To migrate: urlopen() follows redirects by itself; set a custom header with opener = urllib.request.build_opener() and opener.addheaders = [('User-Agent', 'my-bot/1.0')], or with a Request(url, headers={...}) object; authentication comes from an HTTPBasicAuthHandler passed to build_opener().

Examples

# Python 3.14+
import urllib.request
try:
    urllib.request.FancyURLopener
except AttributeError as e:
    print(type(e).__name__)  # → AttributeError
# Python 3.14+
from pathlib import Path
from urllib.request import build_opener
Path('note.txt').write_text('hi')
opener = build_opener()
opener.addheaders = [('User-Agent', 'my-bot/1.0')]
with opener.open(Path('note.txt').resolve().as_uri()) as resp:
    print(resp.read())  # → b'hi'
from pathlib import Path
from urllib.request import FancyURLopener
class Opener(FancyURLopener):
    version = 'my-bot/1.0'
Path('note.txt').write_text('hi')
opener = Opener()
print(opener.open(Path('note.txt').resolve().as_uri()).read())  # → b'hi'

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy