2012-03-12 8 views
2

私はここに小さな問題があります。だから、よく知られているREST APIの呼び出しをいくつか書いています。私はすべての応答をリストとして表示したいという事実を除いて、すべてうまくいっています(私が操作する方が良い)。私は(スプリットを使用するために使用されていますPython:リストとして表示する際の問題httplib.HTTPMessage

import sys, httplib 

HOST = "api.sugarsync.com" 
API_URL = "https://api.sugarsync.com" 

def do_request(xml_location): 
     request = open(xml_location,"r").read() 
     webservice = httplib.HTTPS(HOST) 
     webservice.putrequest("POST", "authorization", API_URL) 
     webservice.putheader("Host", HOST) 
     webservice.putheader("User-Agent","Python post") 
     webservice.putheader("Content-type", "application/xml") 
     webservice.putheader("Content-type", "application/xml") 
     webservice.putheader("Accept", "*/*") 
     webservice.putheader("Content-length", "%d" % len(request)) 
     webservice.endheaders() 
     webservice.send(request) 
     statuscode, statusmessage, header = webservice.getreply() 
     result = webservice.getfile().read() 
     return statuscode, statusmessage, header 
     return result 

do_request('C://Users/my_user/Documents/auth.xml') 

)が、この場合には、結果がこれです::My機能はこれです

[201, 'Created', <httplib.HTTPMessage instance at 0x0000000001F68AC8>] 

まあ、私は第三の目的(httplib.HTTPMessageインスタンスでも必要0x0000000001F68AC8>)をリストとして表示し、その中のいくつかのデータを抽出します。

ありがとうございます!

答えて

0

httplib.HTTPMessageは辞書のようなもので、ここではサンプルです:

import httplib 
from cStringIO import StringIO 

h = httplib.HTTPMessage(StringIO("")) 
h["Content-Type"] = "text/plain" 
h["Content-Length"] = "1234" 

print h.items() 

は、あなたはそれが機能項目(の呼びかけ)、それはヘッダ

のリストを返します。
関連する問題