除了用httpx模块,还可以魔改下requests库
来自大佬Artio的分享
import urllib3.util.ssl_
import requests
urllib3.util.ssl_.DEFAULT_CIPHERS = ":".join(
i for i in urllib3.util.ssl_.DEFAULT_CIPHERS.split(":") if not i.startswith("!"))
from requests import Session
from hyper.contrib import HTTP20Adapter
from requests.utils import CaseInsensitiveDict
_request = Session.request
class MyHttp20Adapter(HTTP20Adapter):
def __init__(self, *args, **kwargs):
super(MyHttp20Adapter, self).__init__(*args, **kwargs)
super(HTTP20Adapter, self).__init__(*args, **kwargs)
def request(self, method, url, clear_headers=False, http2=False, **kwargs):
if http2:
self.mount("https://", MyHttp20Adapter())
if clear_headers:
self.headers = CaseInsensitiveDict()
result = _request(self, method=method, url=url, **kwargs)
return result
r=requests.Session()
r.headers= {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
}
data = {
'page': '2'
}
res=request(r,method="post",url="",http2=True,data=data)
print(res.text)
评论 (0)