使用pyCurl发布问题

rsa*_*avu 3 python webservice-client pycurl

我正在尝试使用CURL将文件发布到Web服务(这是我需要使用的,所以我不能采取扭曲或其他东西).问题是,当使用pyCurl时,web服务不会收到我正在发送的文件,如文件底部注释的情况.我在pyCurl脚本中做错了什么?任何想法?

非常感谢你.

import pycurl
import os

headers = [ "Content-Type: text/xml; charset: UTF-8; " ]
url = "http://myurl/webservice.wsdl"
class FileReader:
    def __init__(self, fp):
        self.fp = fp
    def read_callback(self, size):
        text = self.fp.read(size)
        text = text.replace('\n', '')
        text = text.replace('\r', '')
        text = text.replace('\t', '')
        text = text.strip()
        return text

c = pycurl.Curl()
filename = 'my.xml'
fh = FileReader(open(filename, 'r'))

filesize = os.path.getsize(filename)
c.setopt(c.URL, url)
c.setopt(c.POST, 1)
c.setopt(c.HTTPHEADER, headers)
c.setopt(c.READFUNCTION , fh.read_callback)
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTP_VERSION, c.CURL_HTTP_VERSION_1_0)
c.perform()
c.close()
# This is the curl command I'm using and it works
# curl -d @my.xml -0 "http://myurl/webservice.wsdl" -H "Content-Type: text/xml; charset=UTF-8"
Run Code Online (Sandbox Code Playgroud)

mjh*_*jhm 8

PyCurl似乎是一个孤儿项目.它在两年内没有更新.我只是将命令行curl称为子进程.

import subprocess

def curl(*args):
    curl_path = '/usr/bin/curl'
    curl_list = [curl_path]
    for arg in args:
        # loop just in case we want to filter args in future.
        curl_list.append(arg)
    curl_result = subprocess.Popen(
                 curl_list,
                 stderr=subprocess.PIPE,
                 stdout=subprocess.PIPE).communicate()[0]
    return curl_result 

curl('-d', '@my.xml', '-0', "http://myurl/webservice.wsdl", '-H', "Content-Type: text/xml; charset=UTF-8")
Run Code Online (Sandbox Code Playgroud)