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是若是你的命令出錯的話,錯誤報告直接就刪除了,不會顯示在屏幕上 。 java
搞定!! python