requests测试sanic接口详解

2020年9月18日 06:48 by wst

web开发

起因

一直使用sanic和requests,这个两个工具分属于不同的领域:一个用于服务端写接口,一个用于发请求抓取数据。

由于接口包含签名认证,无法直接用postman进行测试(也许有方法,知道的请赐教)。故使用requests的进行测试。

疑问

在使用过程中有如下疑问:

 在requests中,可携带请求参数的有如下三个参数(详情见这里):

adata -- 可选参数,类型为字典、元组列表、字节串、文件类型的对象;

b. json -- 一个可json化的python对象,将放在请求的body中传送;

c. params -- 可选参数,类型为字典、元组列表、字节串;

1. 这三种方式都有什么区别呢?

2.  服务端是怎么接收这些参数的呢?

实验过程

下面通过实验验证下:

if __name__ == '__main__':
    import time
    param = {
        "start_time": "2020-05-19",
        "end_time": "2020-05-28",
        "union_position_id": ["500907909434639544", "502009057153060303", "80872093216", "80870324108"],
        "channel_id": ["20084", "32004", "3002"]
    }

    timestamp = now_timestamp()
    sign = gen_post_sign(json.dumps(param), timestamp)

    header = {
        "timestamp": str(timestamp),
        "token": sign
    }
    t1 = time.time()

    resp = requests.post("http://xxxxxx.cn/yyyyyy/union/manage",
                        json=param, headers=header)
    t = now_timestamp(unit="ms")
    print(t)
    print(resp.status_code)
    if resp.status_code == 200:
        d = resp.json()
        print(d)

第20行的代码中参数名分别换成json/data/params, 得出的结论如下:

json传参:

request.json:{'start_time': '2020-09-16', 'end_time': '2020-09-17', 'union_position_id': ['80872093216', '80873204095'], 'channel_id': ['20084', '20034']},
request.body:b'{"start_time": "2020-09-16", "end_time": "2020-09-17", "union_position_id": ["80872093216", "80873204095"], "channel_id": ["20084", "20034"]}'

data传参:

request.body:b'start_time=2020-09-16&end_time=2020-09-17&union_position_id=80872093216&union_position_id=80873024095&channel_id=20084&channel_id=20034'
request.json:json parse error;


params传参:

request.body: b''
request.json: None

 

结论

1. json传参比较靠谱,且各种语言都有实现;

2. data是传统的传参方式,也比较常用,只是有些数据json load错误;

3. params中的参数是编码到url里的,所以服务端body为空;


Comments(128) Add Your Comment

Charlesnag
“I haven’t seen you in these parts,” the barkeep said, sidling settled to where I sat. “Personage’s Bao.” He stated it exuberantly, as if word of his exploits were shared by settlers about multitudinous a verve in Aeternum. He waved to a unanimated hogshead apart from us, and I returned his gesticulate with a nod. He filled a glass and slid it to me across the stained red wood of the court prior to continuing. “As a betting chains, I’d be willing to wager a adequate speck of invent you’re in Ebonscale Reach for the purpose more than the carouse and sights,” he said, eyes glancing from the sword sheathed on my in to the capitulate slung across my back. https://www.google.az/url?q=https://renewworld.ru/sistemnye-trebovaniya-new-world/
Kevingaw
https://www.merkur-zeitschrift.de/wp-content/pages/die_besten_casinos_in_las_vegas_auf_dem_strip.html https://images.google.dz/url?q=https://www.hille-eventservice.de/news/wettannahmestellen_in_polen.html http://tanzschule-schrittfest.de/wp-content/pages/welche_online_casinos_sind_in_deutschland_legal__2.html https://www.karl-georg.de/tmp/welches_casino_zahlt_am_schnellsten_aus______die_ehrlichsten_vertrauensw_rdigen_casinos.html http://images.google.com.ng/url?q=https://1xbitapk.com/hi/
Hmmknt
lipitor pills <a href="https://lipiws.top/">buy atorvastatin 80mg pills</a> lipitor 80mg sale
Akxsla
oral cipro 1000mg - <a href="https://cipropro.top/">buy baycip without a prescription</a> buy generic augmentin
Vsqqxj
cipro uk - <a href="https://metroagyl.top/oxytetracycline/">cheap myambutol 1000mg</a> augmentin 375mg drug
Igvvkv
order flagyl pill - <a href="https://metroagyl.top/azithromycin/">zithromax over the counter</a> zithromax 500mg pills
Ndmrdl
order ciplox 500mg for sale - <a href="https://septrim.top/tinidazole/">tindamax generic</a> buy erythromycin 500mg pills
Gcovkm
valtrex pills - <a href="https://gnantiviralp.com/diltiazem/">purchase diltiazem</a> order zovirax 800mg
Gdjspf
stromectol order online - <a href="https://keflexin.top/amoxiclav/">amoxiclav order online</a> buy generic tetracycline for sale
Lbkhtq
cost flagyl 400mg - <a href="https://metroagyl.top/azithromycin/">azithromycin 500mg price</a> buy zithromax no prescription
Pvqmzm
ampicillin buy online <a href="https://ampiacil.top/">order ampicillin online</a> buy amoxicillin without prescription
Ixyrev
order furosemide 100mg pills - <a href="https://antipathogenc.com/medex/">order warfarin sale</a> order capoten generic
Ufaxbp
glucophage brand - <a href="https://gnantiacidity.com/septra/">bactrim 960mg generic</a> buy lincocin 500mg pill
Ozigur
buy generic retrovir over the counter - <a href="https://canadiangnp.com/rulide/">order roxithromycin online</a> zyloprim sale
Wwfcyi
order clozaril online cheap - <a href="https://genonlinep.com/altace/">tritace price</a> generic famotidine 40mg
Zsrjag
quetiapine 100mg pill - <a href="https://gnkantdepres.com/geodon/">geodon 40mg uk</a> eskalith online
Whnvqt
buy generic anafranil - <a href="https://antdeponline.com/paxil/">buy paroxetine online cheap</a> sinequan 75mg without prescription
Fqsbjl
brand hydroxyzine - <a href="https://antdepls.com/endep/">buy endep 25mg online cheap</a> order endep 25mg
Lexwuu
buy augmentin 625mg generic - <a href="https://atbioinfo.com/">augmentin ca</a> order baycip for sale
Apckka
amoxil over the counter - <a href="https://atbioxotc.com/erythromycin/">buy erythromycin 250mg</a> cipro 1000mg brand
Hijobd
cleocin order - <a href="https://cadbiot.com/oxytetracycline/">buy generic terramycin online</a> chloramphenicol ca
Gkdmoy
zithromax online - <a href="https://gncatbp.com/dofloxacin/">floxin cost</a> order ciprofloxacin online cheap
Zqhzzr
ivermectin 3mg over counter - <a href="https://antibpl.com/szdoryx/">order doryx online cheap</a> buy cefaclor capsules for sale
Fexmxr
ventolin medication - <a href="https://antxallergic.com/oiphenergan/">buy promethazine pill</a> buy generic theo-24 Cr 400 mg
Zblbcj
purchase desloratadine for sale - <a href="https://rxtallerg.com/">buy generic clarinex</a> order ventolin online
Tkizwb
methylprednisolone 8 mg tablet - <a href="https://ntallegpl.com/montelukast/">order singulair 10mg pill</a> buy azelastine generic
Ioxppw
buy generic micronase - <a href="https://prodeprpl.com/pioglitazone30/">purchase actos without prescription</a> buy dapagliflozin generic
Xikexy
buy repaglinide 1mg - <a href="https://depressinfo.com/">prandin 2mg pills</a> buy empagliflozin pills for sale
Skefmc
glycomet 500mg without prescription - <a href="https://arxdepress.com/sitagliptin50/">januvia 100mg drug</a> buy precose medication
Zcjlec
order generic terbinafine - <a href="https://treatfungusx.com/xgrifulvinvs/">griseofulvin price</a> cost griseofulvin
Xncvjm
purchase rybelsus without prescription - <a href="https://infodeppl.com/ddavpspray/">order generic DDAVP</a> buy cheap DDAVP
Xdzylv
nizoral buy online - <a href="https://antifungusrp.com/clotrithasone/">purchase lotrisone</a> buy sporanox no prescription
Evbcje
famvir brand - <a href="https://amvinherpes.com/gnvalaciclovir/">buy valcivir 1000mg for sale</a> valaciclovir 1000mg ca
Fgpado
digoxin price - <a href="https://blpressureok.com/dipyridamole100/">dipyridamole 25mg usa</a> order furosemide 100mg online cheap
Byzwar
microzide us - <a href="https://norvapril.com/amlodipine/">norvasc over the counter</a> order zebeta online
Pqdjmh
metoprolol 100mg sale - <a href="https://bloodpresspl.com/nifedipine/">buy cheap generic nifedipine</a> buy nifedipine 10mg without prescription
Axnfzh
order nitroglycerin without prescription - <a href="https://nitroproxl.com/indapamide/">lozol tablet</a> diovan 80mg brand
Dxasks
crestor baby - <a href="https://antcholesterol.com/caduet5mg/">caduet pills stand</a> caduet sip
Ermjay
simvastatin reveal - <a href="https://canescholest.com/">zocor limb</a> lipitor under
Xpehgq
viagra professional online whip - <a href="https://edsildps.com/viagragold/">buy viagra gold central</a> levitra oral jelly soldier
Gixaty
dapoxetine hill - <a href="https://promedprili.com/">dapoxetine jewel</a> cialis with dapoxetine tradition
Brvclp
cenforce suffer - <a href="https://xcenforcem.com/tadaciptadalafil/">tadacip online waste</a> brand viagra online choke
Kjkjhs
brand cialis chatter - <a href="https://probrandtad.com/penisole/">penisole devote</a> penisole son
Zbtzts
cialis soft tabs pills league - <a href="https://supervalip.com/valifonline/">valif online lip</a> viagra oral jelly online gradual
Zpxiim
brand cialis halfway - <a href="https://probrandtad.com/apcalissx/">apcalis amidst</a> penisole wing
Cklgls
cialis soft tabs accomplish - <a href="https://supervalip.com/viagrasuperactive/">viagra super active online beer</a> viagra oral jelly bang
Xjvjku
cenforce online ice - <a href="https://xcenforcem.com/zenegrasildenafil/">zenegra online avoid</a> brand viagra serious
Fflinl
priligy delight - <a href="https://promedprili.com/levitrawithdapoxetine/">levitra with dapoxetine east</a> cialis with dapoxetine wade
Asxmzq
acne medication frown - <a href="https://placnemedx.com/">acne treatment glisten</a> acne treatment hospital
Rucrnz
asthma treatment foe - <a href="https://bsasthmaps.com/">inhalers for asthma hood</a> inhalers for asthma tonight
Hxyllb
treatment for uti egg - <a href="https://amenahealthp.com/">treatment for uti mad</a> treatment for uti inspire
Yxkopg
pills for treat prostatitis player - <a href="https://xprosttreat.com/">prostatitis pills bulge</a> prostatitis treatment nightmare
Irxbmc
valacyclovir angle - <a href="https://gnantiviralp.com/">valacyclovir pills beam</a> valtrex wit
Kdgrwn
claritin storm - <a href="https://clatadine.top/">claritin pills sniff</a> claritin pills pippin
Efihfm
dapoxetine credit - <a href="https://prilixgn.top/">dapoxetine wreck</a> dapoxetine release
Nhlpbc
claritin pills bosom - <a href="https://clatadine.top/">claritin trail</a> claritin upon
Mazhgf
ascorbic acid instruction - <a href="https://ascxacid.com/">ascorbic acid silence</a> ascorbic acid bulge
Ckjklo
promethazine valentine - <a href="https://prohnrg.com/">promethazine damage</a> promethazine stiff
Nyklin
biaxin twist - <a href="https://gastropls.com/gncytotec/">cytotec pills table</a> cytotec filch
Skwlwq
florinef pills your - <a href="https://gastroplusp.com/propantoprazole/">protonix home</a> prevacid goodness
Xgljzl
rabeprazole where to buy - <a href="https://gastrointesl.com/domperidone/">buy cheap generic motilium</a> brand motilium
Hbzxsj
bisacodyl 5 mg ca - <a href="https://gastroinfop.com/liv52/">buy liv52 20mg pills</a> liv52 online
Cothgd
cotrimoxazole 480mg without prescription - <a href="https://cotrioxazo.com/">oral cotrimoxazole</a> tobramycin 10mg cheap
Jkdvhq
purchase zovirax online - <a href="https://cerazestrel.com/">buy desogestrel without a prescription</a> duphaston canada
Lenryx
forxiga pills - <a href="https://precarbos.com/">precose 25mg canada</a> buy acarbose 25mg generic
Qdcfou
buy fulvicin pills for sale - <a href="https://dipyrilx.com/">dipyridamole 25mg over the counter</a> buy gemfibrozil 300 mg generic
Qkuqur
brand dimenhydrinate - <a href="https://bisacolax.com/">buy generic dimenhydrinate over the counter</a> buy actonel pills
Rutqgy
enalapril 5mg uk - <a href="https://vasolapril.com/">how to buy enalapril</a> purchase latanoprost without prescription
Ylmkuo
buy etodolac generic - <a href="https://etodograph.com/">etodolac 600mg drug</a> cilostazol 100 mg cost
Bvlemq
buy feldene pills for sale - <a href="https://rivastilons.com/">buy exelon generic</a> oral rivastigmine
Bbmthz
nootropil ca - <a href="https://nootquin.com/levofloxacin/">buy levofloxacin 250mg for sale</a> buy generic sinemet
Aialkh
buy hydroxyurea online cheap - <a href="https://hydroydrinfo.com/indinavir/">crixivan buy online</a> methocarbamol 500mg pill
Cevyex
divalproex 500mg cost - <a href="https://adepamox.com/">purchase divalproex pills</a> topamax price
Uiwjah
where can i buy disopyramide phosphate - <a href="https://anorpica.com/">cheap disopyramide phosphate pill</a> chlorpromazine 50 mg pills
Zhgbzn
buy generic cyclophosphamide for sale - <a href="https://cycloxalp.com/antivert/">buy antivert pills for sale</a> cheap vastarel tablets
Dcsoaj
cheap spironolactone 25mg - <a href="https://aldantinep.com/">spironolactone 100mg for sale</a> purchase revia without prescription
Vsxdpf
buy cheap cyclobenzaprine - <a href="https://abflequine.com/primaquine/">buy primaquine without a prescription</a> buy generic enalapril 10mg
Agumce
how to get zofran without a prescription - <a href="https://azofarininfo.com/procyclidine/">kemadrin without prescription</a> requip online
Dehyty
order ascorbic acid 500mg online cheap - <a href="https://mdacidinfo.com/ferroussulfate/">ferrous 100mg us</a> buy compro without prescription
Yorypw
durex gel where to purchase - <a href="https://xalaplinfo.com/durexcondoms/">durex condoms online purchase</a> xalatan canada
Vqxzoo
minoxidil online - <a href="https://hairlossmedinfo.com/">buy minoxidil generic</a> purchase finasteride generic
Kmwdcb
cost arava 20mg - <a href="https://infohealthybones.com/risedronate/">actonel 35 mg pill</a> buy cartidin generic
Logykv
order tenormin 100mg online cheap - <a href="https://heartmedinfox.com/clopidogrel/">order plavix 150mg without prescription</a> buy carvedilol
Ejgnxq
verapamil oral - <a href="https://infoheartdisea.com/">verapamil pills</a> cheap tenoretic without prescription
Omfuji
atorlip price - <a href="https://infoxheartmed.com/lisinopril/">lisinopril price</a> brand bystolic 20mg
Lfevbj
cheap lasuna online - <a href="https://infoherbalmz.com/">cheap lasuna sale</a> buy generic himcolin
Nxiutq
buy noroxin tablets - <a href="https://gmenshth.com/confido/">cheap confido online</a> buy confido pills for sale
Mivjgi
speman usa - <a href="https://spmensht.com/">speman price</a> purchase fincar generic
Rirshs
cost finasteride - <a href="https://finmenura.com/">order finax pill</a> buy alfuzosin paypal
Wzmugw
hytrin tablet - <a href="https://hymenmax.com/dapoxetine/">order dapoxetine 90mg online cheap</a> priligy 60mg pills
Kreaif
order generic oxcarbazepine 600mg - <a href="https://trileoxine.com/levothyroxine/">order generic levothyroxine</a> order synthroid online cheap
Lzselw
imusporin order - <a href="https://asimusxate.com/">imusporin for sale online</a> colchicine over the counter
Zecbjb
lactulose cheap - <a href="https://duphalinfo.com/betahistine/">betahistine 16 mg drug</a> buy betahistine sale
Mkbgwb
purchase deflazacort - <a href="https://lazacort.com/brimonidine/">buy alphagan without prescription</a> how to buy alphagan
Hoqbwv
buy neurontin 800mg online cheap - <a href="https://aneutrin.com/">cheap neurontin for sale</a> azulfidine generic
Aotfjl
order probenecid pills - <a href="https://bendoltol.com/carbamazepine/">oral tegretol 400mg</a> tegretol uk
Eflech
celebrex 100mg pills - <a href="https://celespas.com/flavoxate/">purchase flavoxate without prescription</a> indomethacin 75mg without prescription
Rlacdx
buy colospa online - <a href="https://coloxia.com/">colospa uk</a> order cilostazol pills
Vuwhih
buy diclofenac 50mg online cheap - <a href="https://dicloltarin.com/aspirin/">purchase aspirin online</a> purchase aspirin without prescription
Azzzgu
order rumalaya sale - <a href="https://rumaxtol.com/">buy cheap rumalaya</a> endep 50mg price
Jmnsjn
mestinon over the counter - <a href="https://mestonsx.com/asumatriptan/">sumatriptan oral</a> azathioprine price
Iuzxqb
voveran buy online - <a href="https://vovetosa.com/animodipine/">order nimodipine online</a> nimotop order
Dvhpyy
baclofen where to buy - <a href="https://baclion.com/">baclofen oral</a> feldene online buy
Kfnhwy
order meloxicam 15mg sale - <a href="https://meloxiptan.com/">buy mobic 15mg</a> toradol 10mg usa
Rvhjrh
periactin cheap - <a href="https://periheptadn.com/">cyproheptadine 4mg oral</a> purchase tizanidine pill
Rpaarl
trihexyphenidyl usa - <a href="https://voltapll.com/diclofenacgel/">where can i purchase emulgel</a> buy emulgel sale
Gbgtzg
order cefdinir online cheap - <a href="https://omnixcin.com/">purchase omnicef generic</a> clindamycin canada
Cbjdkf
isotretinoin 10mg tablet - <a href="https://aisotane.com/asdeltasone/">cost deltasone 40mg</a> order generic deltasone 5mg
Auhecp
brand prednisone - <a href="https://apreplson.com/prednisolone/">omnacortil 20mg tablet</a> buy elimite cream
Wcxlgj
order permethrin generic - <a href="https://actizacs.com/asbenzac/">buy benzoyl peroxide sale</a> retin cream brand
Uixqvm
betnovate usa - <a href="https://betnoson.com/benoquincre/">purchase monobenzone online cheap</a> order monobenzone sale
Myaije
order metronidazole 400mg for sale - <a href="https://ametronles.com/">cost metronidazole 200mg</a> order cenforce 50mg sale
Nbanlj
order augmentin 625mg for sale - <a href="https://alevonted.com/">synthroid 75mcg uk</a> buy levothyroxine pills for sale
Iuotbz
clindamycin tablet - <a href="https://clinycinpl.com/">buy generic cleocin</a> cheap indocin 50mg
Olxnct
generic losartan 50mg - <a href="https://cozartan.com/">where to buy losartan without a prescription</a> order cephalexin 125mg pills
Wltxzj
crotamiton generic - <a href="https://aeuracream.com/">eurax brand</a> order aczone online
Gxhuir
modafinil order - <a href="https://sleepagil.com/">provigil 200mg tablet</a> brand melatonin 3 mg
Mxbpuq
where to buy zyban without a prescription - <a href="https://bupropsl.com/orlistat/">buy xenical 120mg for sale</a> shuddha guggulu tablets
Slkowk
buy capecitabine paypal - <a href="https://xelocap.com/danocrine/">brand danazol 100mg</a> danocrine sale
Wmoyey
progesterone 200mg uk - <a href="https://apromid.com/clomiphene/">order clomiphene 50mg pills</a> buy clomiphene online cheap
Ajttnb
generic alendronate - <a href="https://pilaxmax.com/">alendronate 70mg cheap</a> cost provera 5mg
Tvrzrq
buy norethindrone generic - <a href="https://norethgep.com/bimatoprost/">careprost spray</a> order yasmin pill
Cwvhyg
dostinex buy online - <a href="https://adostilin.com/">buy dostinex for sale</a> how to buy alesse
Pstpxq
purchase yasmin pills - <a href="https://festrolp.com/">buy estradiol pill</a> arimidex ca
Bjqyfu
シルデナフィル 副作用 - <a href="https://jpedpharm.com/">シルデナフィル 値段</a> タダラフィルジェネリック 通販
Qjdisv
プレドニン通販おすすめ - <a href="https://jpaonlinep.com/jazithromycin/">アジスロマイシン 値段</a> アジスロマイシン の購入
Mlqnia
プレドニン錠 20 mg 強さ - <a href="https://jpanfarap.com/jpadoxycycline/">ドキシサイクリン 副作用</a> イソトレチノインの購入
Qfcreg
eriacta peter - <a href="https://eriagra.com/dapcalisb/">apcalis afterward</a> forzest collapse