curl --header "MLS: uid:xxxxx;ip:xxx.xx.xx" v.mls.com/gl/get_gl -d "pid=409&offset=0&limit=480" #此为伪命令 #返回值 {"error_code":0,"data":{"tids":[1746922055,1746931247,1708272843],"usable_num":12082,"show_num":12464}} # error_code=0 表示正常
cmd = ''' curl --header "MLS: uid:xxxxx;ip:xxx.xx.xx" v.mls.com/gl/get_gl -d "pid=409&offset=0&limit=480" ''' #此为伪命令 result = json.loads( os.system(cmd) ) result['data']['tids']# 异常 TypeError: expected string or buffer。可能是os.system()命令返回的类型不符,查了下Python文档"On Unix, the return value is the exit status of the process encoded in the format specified for wait()"
cmd = ''' curl --header "MLS: uid:xxxxx;ip:xxx.xx.xx" v.mls.com/gl/get_gl -d "pid=409&offset=0&limit=480" ''' #此为伪命令 result = json.loads( commands.getoutput(cmd) ) result['data']['tids']#异常 ValueError: No JSON object could be decoded。
cmd = ''' curl --header "MLS: uid:xxxxx;ip:xxx.xx.xx" v.mls.com/gl/get_gl -d "pid=409&offset=0&limit=480" 2>/dev/null ''' #此为伪命令 result = json.loads( commands.getoutput(cmd) ) result['data']['ties']
##### 2>/dev/null是如果你的命令出错的话,错误报告直接就删除了,不会显示在屏幕上 。
搞定!!