用于在同步模式下收集http请求的小型aiohttp包装器
async-fetcher的Python项目详细描述
安装
pip install async-fetcher # or pip install -e git+https://github.com/night-crawler/async-fetcher.git@#egg=async-fetcher
样品
af=AsyncFetch({'first':AsyncFetch.mk_task(build_url('request-info')),'second':AsyncFetch.mk_task('http://example.com/'),'fail':AsyncFetch.mk_task(build_url('404'))})responses=af.go()
mk_task静态方法可以接受以下参数:
:paramfail_silently:bool,donotraiseexceptions,defaultisFalse;fortestpurpose,donotuseinproduction:paramnum_retries:int,*optional*,defaultis-1;-1-noretries;0-useAsyncFetch.num_retries:paramautodetect_content_type:ifno`content-type`headerwasspecified,set`content-type`as`application/json`fordict,and`text/html`otherwise;defaultisTrue:paramjson_encoder:JSONEncoder,*optional*,JSONencoderfordataserializationtriestouseDRF's encoder, or default JSONEncoder from json package; default is JSONEncoder:paramurl:str,*required*,urladdress:paramapi_key:str,optionalAPIkeypassedintoHEADERSdict:paramdata:dict,*optional*,requestdata.DefaultisNone,:parammethod:str,*optional*,HTTPrequestmethod.DefaultisTrue.:paramheaders:dict,*optional*,optionalHTTPheaders:paramresponse_type:str,*optional*,HTTPresponsetype(infactit's just aiohttp'smethodname,i.e.text,orjson);defaultis'json':paramlanguage_code:str,set`accept-language`header:paramtimeout:float,*optional*,timetowaitforresponseinsecondsbeforeTimeoutError:paramquery:dict,*optional*,urlgetarguments:paramdo_not_wait:bool,*optional*,failsilentlywithnoretriesandemptyresultset
af0=AsyncFetch({})tcp_connector=af0.get_tcp_connector()af1=AsyncFetch({'1':AsyncFetch.mk_task(build_url('request-info')),'2':AsyncFetch.mk_task(build_url('request-info')),},tcp_connector=tcp_connector)responses=af1.go()