0

i need to receive an file through CURL in webpy

import web
import json

class GetFile:

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

I am not sure how to do this because there is no example to receive an data from CURL

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

I am getting an issue

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

can any one give me an example code to upload an file through curl and save it in a location.

Kathick
  • 1,395
  • 5
  • 19
  • 30

2 Answers2

1

To fetch a file use urlib

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

To upload a file, make sure to mark the contet as multipart form data:

curl -X POST -H "Content-Type: multipart/form-data;" --data-binary @doc.xml http://localhost:2332/upload
Community
  • 1
  • 1
Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65
  • I am not sure about your solution i am trying to make an API with webpy where i need to receive a file and give an respond for successive receive – Kathick Oct 19 '12 at 14:15
  • Refer http://stackoverflow.com/questions/11137946/python-extracting-binary-from-a-post-request-using-web-py – Pratik Mandrekar Oct 19 '12 at 14:52
0

The problem is that the -T option to curl uses the PUT method by default, and you have only implemented a POST handler. You could try it with a -X POST, or investigate the -d and related options as alternatives to -T, which will use POST by default.

Or, you could add a PUT handler to your class, if it was your intention to use the PUT method to upload the files.

randomhuman
  • 547
  • 4
  • 11