2017-08-02 69 views
0

我正在關注this以重新啓動處於INSTALLED狀態的Ambari組件,因爲我已經使用Pycurl編寫了解析Ambari服務的Python代碼。Ambari CURL命令的Python Pycurl POST方法問題

但是一旦JSON解析我會產生像JSON文件:

{ 
"RequestInfo": { 
    "command": "START", 
    "context": "Restart all components on HOST" 
}, 
"Requests/resource_filters": [ 
    { 
    "component_name": "NAMENODE", 
    "hosts": "hadoopm", 
    "service_name": "HDFS" 
    }, 
    { 
    "component_name": "RESOURCEMANAGER", 
    "hosts": "hadoopm", 
    "service_name": "YARN" 
    }]} 

這個作品有:

curl -u username:password -H 'X-Requested-By-ambari' http://ambariserver:8080/api/v1/clusters/CLUSTERNAME/requests [email protected] 

但同樣不能正常工作,並與400錯誤的請求錯誤失敗與下面的代碼:

import pycurl 
c = pycurl.Curl() 
c.setopt(pycurl.URL, url_post) 
c.setopt(pycurl.HTTPHEADER, ["X-Requested-By:ambari"]) 
data = json.dumps(json.loads(open(output_temp_file,'rb').read()), indent=1, sort_keys=True) 
tabs = re.sub('\n +', lambda match: '\n' + '\t' * (len(match.group().strip('\n'))/2), data) 
tabJSON=json.dumps(json.loads(open(output_temp_file,'rb').read()), indent=1, sort_keys=True) 
c.setopt(pycurl.POST, 1) 
c.setopt(pycurl.USERPWD,'admin:'+admin_pass) 
c.setopt(pycurl.POSTFIELDS, 'tabJSON') 
c.setopt(pycurl.WRITEFUNCTION, service_buffer.write) 
c.setopt(pycurl.VERBOSE, 1) 
c.perform() 
c.close() 

和故障HTTP/1 .1 400錯誤請求

有沒有什麼不對,我正在做這件事可以有人請幫我這個。

+0

當您從python發送請求時,ambari-server.log中有什麼消息? – thinkmassive

回答

1

可能的API調用格式在文檔中已過時。我想通過實例建議去:在Chrome

  • 開放,開發者控制檯
  • 使用Ambari UI執行動作(如重新啓動所有服務)
  • Network,找到相關的POST/PUT請求(排序非200 Status列)
  • 複製請求(右鍵單擊請求 - >Copy - >copy as cURL

現在你必須跟上時代的curl命令例如nd可以繼續玩請求主體