python httpx支持访问http2
作者:互联网
- 安装包
pip install httpx[http2]
- demo
requests 包无法访问http2的server,httpx 支持,只需要设施http2=True 即可
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'))
标签:__,get,python,response,http2,import,httpx 来源: https://blog.csdn.net/weixin_43632687/article/details/121848706