Overview

Requests 2.27, released on January 4, 2022, officially deprecates Python 2 support and introduces charset_normalizer as an optional dependency.

Main Features

Python 2 deprecation

This version emits a warning when used with Python 2. Future Requests versions will drop Python 2 support, encouraging migration to Python 3.

python
import requests

# Simple GET request
response = requests.get('https://httpbin.org/get')
print(response.status_code)  # 200
print(response.json()['origin'])

# POST request with JSON
data = {'name': 'Alice', 'age': 30}
response = requests.post('https://httpbin.org/post', json=data)
print(response.json()['json'])  # {'name': 'Alice', 'age': 30}

charset_normalizer

The charset_normalizer library progressively replaces chardet for encoding detection. It is faster and MIT-licensed.

python
import requests

# charset_normalizer detects encoding automatically
response = requests.get('https://httpbin.org/encoding/utf8')
print(response.encoding)  # utf-8 (auto-detected)
print(response.apparent_encoding)  # utf-8

# Force encoding if needed
response.encoding = 'utf-8'
print(len(response.text))

Sources