【问题标题】:receiving a file through curl webpy通过 curl webpy 接收文件
【发布时间】:2012-10-19 12:00:05
【问题描述】:

我需要在 webpy 中通过 CURL 接收文件

import web
import json

class GetFile:

    def POST(self):
        try:
            i = web.input()
            data = web.data() 
        except Error(e):
            print e

我不知道该怎么做,因为没有从 CURL 接收数据的示例

curl -o -H "Content-type: text/xml; charset=utf-8" -T doc.xml "http://localhost:8080/get_file

我遇到了问题

HTTP/1.1 405 Method Not Allowed
Content-Type: text/html
Allow: GET
Transfer-Encoding: chunked
Date: Fri, 19 Oct 2012 11:54:13 GMT
Server: localhost

谁能给我一个示例代码,通过 curl 上传文件并将其保存在某个位置。

【问题讨论】:

    标签: python web.py


    【解决方案1】:

    使用 urllib 获取文件

    import urllib2
    response = urllib2.urlopen('http://www.example.com/')
    html = response.read()
    

    要上传文件,请务必将内容标记为multipart form data

    curl -X POST -H "Content-Type: multipart/form-data;" --data-binary @doc.xml http://localhost:2332/upload
    

    【讨论】:

    【解决方案2】:

    问题在于 curl 的 -T 选项默认使用 PUT 方法,而您只实现了一个 POST 处理程序。您可以使用-X POST 尝试它,或者调查-d 和相关选项作为-T 的替代品,默认情况下将使用POST。

    或者,如果您打算使用 PUT 方法上传文件,您可以向您的类添加一个 PUT 处理程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多