程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python+requests build request tips

編輯:Python

requests Library help documentation

website :http://cn.python-requests.org/zh_CN/latest/

【 summary 1】: How to construct request body data

formula 1:params Parameters , If you pass in a dictionary , Auto code as form .— Aiming at get Method
formula 2:data Parameters , If you pass in a dictionary , Auto code as form .— Aiming at post/put Method
formula 3:data Parameters , If a string is passed in , Publish directly in the original format .— Aiming at post/put Method
formula 4:json Parameters , If you pass in a dictionary , The automatic code is json character string .— Aiming at post/put Method
formula 5:json Parameters , If a string is passed in , Add double quotation marks on the basis of the original format and publish it .— Aiming at post/put Method
formula 6:headers Parameters , The dictionary format is passed — For all methods
data=json.dumps(dictPayload) Equate to json=dictPayload

【 summary 2- a key 】 How to construct the request according to the interface document

1、 If it is get request , Because it has only one params Parameters , So according to the formula 1 Construction request ok.
2、 If it is post perhaps put request , The formula is :1 see 2 look for 3 structure .
1 see = See the interface document clearly content-type The format of the message body is required . The form format is still json Format ?
2 look for = according to 1 see , Use the format you see to find the formula , The pithy formula is mainly 2、3( or 7), Find the corresponding formula
3 structure = according to 2 look for , Find the formula to construct the request parameters .
It is worth noting that , Note that dictionaries are nested in dictionaries , Nested dictionaries may also be converted into forms !!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved