我试图使用python(pycurl)自动化curl put / delete / get到xml的应用程序

时间:2016-03-03 07:07:41

标签: python curl pycurl

我有一个卷曲声明:     curl -v -X PUT --header“Expect:” - header“X-XCAP -Asserted-Identity:\”sip:14257701100@msg.lab.t-mobile.com \“” - header“Content-Type :application / auth-policy + xml“--header”User-Agent:Web-Serv-Gateway-v1“--header”Content-Encoding:gzip“-T 14257701100_AccessRule_gzip.xml.gz http://10.3.11.142:8060/cdb/xcap/org.openmobilealliance.access-rules/users/sip:1100@mavenir.lab/access-rules

我试图使用python来自动化请求。但是PUT请求使用下面的代码失败,因为没有发送数据(xml)。但我读取数据并传递如下。

#!/usr/bin/python

import os
import commands
import string
import subprocess
import urllib2
import pycurl
import StringIO

xml1=open('14257701100_GroupInfo.xml','r+')
xmldata=xml1.read()
print(xmldata)
response = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://10.3.11.142:8060/cdb/xcap/org.openmobilealliance.groups/users/sip:14257701100@msg.lab.t-mobile.com/list-service')
#c.setopt(c.URL, 'http://110.3.11.142:8060/cdb/xcap/org.openmobilealliance.groups/users/sip:14257701100@msg.lab.t-mobile.com/list-service')
c.setopt(c.WRITEFUNCTION, response.write)
c.setopt(c.HTTPHEADER, ['X-XCAP-Asserted-Identity: \"sip:14257701100@msg.lab.t-mobile.com\"','Content-Type: application/vnd.oma.poc.groups+xml','User-Agent: Web-Serv-Gateway-v1'])
c.setopt(c.CUSTOMREQUEST,"PUT")
c.setopt(c.PUT,True)
c.setopt(pycurl.POSTFIELDS,xmldata)
try:
    c.perform()
except pycurl.error, e:
    raise e
http_code = c.getinfo(pycurl.HTTP_CODE)
print('HTTP CODE IS: %d',http_code)
c.close()
print('done')

####

在应用程序日志中,xml数据为空。

由于 Shrinidhi

0 个答案:

没有答案