接口測試返回值的具體內容


http://www.robotframework.net/?/article/91

 

運行這段腳本,第4行的打印結果是:INFO : <class 'requests.models.Response'>
從結果可以看出${resp}是一個類對象,源碼可在requests/models/Response查看,對象句點操作一般是取對象屬性,順藤摸瓜,找出該類的所有屬性,第6行打印結果:
 ['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed', 'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines', 'json', 'links', 'ok', 'raise_for_status', 'raw', 'reason', 'request', 'status_code', 'text', 'url']

粗體的是比較重要的,今后會被頻繁使用的屬性:

content: 響應body的內容,二進制編碼,如果返回只有文本內容,和text差不多
cookies:響應回寫的cookies,cookieJar類對象
headers: 響應頭內容
json(): 響應body內容,json格式
status_code: 狀態碼
text: 響應body的內容,默認unicode編碼

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM