如何将此cURL命令转换为python脚本?

时间:2017-09-12 01:31:11

标签: python curl post

@Override
public View getChildView(int groupPosition, int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {
    final CustomExpListView secondLevelExpListView = new CustomExpListView(this.mContext);
    String parentNode = (String) getGroup(groupPosition);
    secondLevelExpListView.setAdapter(new SecondLevelAdapter(this.mContext, mListData_SecondLevel_Map.get(parentNode), mListData_ThirdLevel_Map));
    secondLevelExpListView.setGroupIndicator(null);

//newcode
    secondLevelExpListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener(){
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,long id)
        { String selectText = ((TextView) v).getText().toString();
           switch (selectText){
               case "ItemName  you want to do something with":
                   //Actions you want to do when clicking this item
                   break;
               case "ItemName2  you want to do something with":
                   //Actions you want to do when clicking this second item
                   break;
               default:
                   //default actions on all other items
        }

            return false;}
    });

    return secondLevelExpListView;
}

这是命令。

2 个答案:

答案 0 :(得分:3)

这个示例脚本怎么样?

示例脚本:

import json
import requests

url = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
payload = {
    "client_id": "535fb089-9ff3-47b6-9bfb-4f1264799865",
    "client_secret": "qWgdYAmab0YSkuL1qKv5bPX",
    "grant_type": "client_credentials",
    "scope": "https://graph.microsoft.com/.default"
}
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}
res = requests.post(url, headers=headers, data=json.dumps(payload))
print(res.text)

如果我误解了你的问题,我很抱歉。

答案 1 :(得分:1)

您可以使用操作系统(虽然它过时了)

import os 
os.system("curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'client_id=535fb089-9ff3-47b6-9bfb-4f1264799865&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret=qWgdYAmab0YSkuL1qKv5bPX&grant_type=client_credentials' 'https://login.microsoftonline.com/common/oauth2/v2.0/token'")