pip install httpx[http2]
import httpx import requests res= requests.get('https://spa16.scrape.center/',verify=False) print(res.status_code) with httpx.Client(http2=True) as clients: response = clients.get('https://spa16.scrape.center/') print(response.text)
异步
import httpx import asyncio async def test(url): async with httpx.AsyncClient(http2=True) as client: response = await client.get(url) print(response.status_code) if __name__=='__main__': asyncio.get_event_loop().run_until_complete(test('https://www.httpbin.org/get'))