0

基本的に「テンプレート」からファイルを取得してskytapの「構成」に入れるPythonでPOSTリクエストを作成しようとしていますが、PythonでのPOSTリクエストでいくつかの問題に直面しています。コードは次のようになります。

import urllib,urllib2, base64, cookielib
cookie_jar=cookielib.LWPCookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
urllib2.install_opener(opener)
#--------------
url="http://cloud.skytap.com/configurations"
values={"template_id":"1234"}
authentication=base64.b64encode("username:password")
header={"Authorization":"Basic %s"%authentication, "Accept":"application/json","Content-Type":"application/json"}
data=urllib.urlencode(values)
req=urllib2.Request(url,data,header)
res=urllib2.urlopen(req)
the_page=res.read()
print the_page

しかし、出力が POST に渡されるはずだった新しいリソースをまだ返していないため、問題が発生している場所をデバッグする方法がわかりません。より多くの視点を得るために、出力は次のようになります

[{template:123124,name:abc} <-- already existing template 
,{template:1234,name:new_template}]

しかし、私が得ているのは

[{template:123124,name:abc}]

この問題を解決するのに役立つ助けに感謝します

編集: Python で requests モジュールを使用して同じことを試しましたが、まだ機能しません。私が愚かな間違いを犯していないことを確認するために、そのコードを次に示します。

r=requests.post(url,data=json.dumps(values),headers=header)
4

0 に答える 0