Reputation: 1405
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.
Upvotes: 0
Views: 534
Reputation: 557
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.
Upvotes: 0
Reputation: 9568
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
Upvotes: 1