Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.055 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restful': 0.09; 'bug': 0.10; 'url:blog': 0.10; 'python': 0.10; 'suggest': 0.15; '(windows': 0.16; '...)': 0.16; 'from:addr:steve': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:File': 0.16; 'substituting': 0.16; 'wrote:': 0.16; 'example.': 0.18; 'steve': 0.18; 'thanks.': 0.18; '>>>': 0.20; '2015': 0.20; 'permission': 0.20; 'file.': 0.22; 'trying': 0.22; 'seems': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'requests': 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'linux': 0.26; 'rest': 0.26; 'question': 0.27; "skip:' 10": 0.28; 'went': 0.28; 'fine': 0.28; 'initial': 0.28; 'tutorial': 0.29; "i'm": 0.30; 'code': 0.30; 'posts': 0.30; 'post': 0.31; 'file': 0.34; 'server': 0.34; 'list': 0.34; 'behind': 0.35; 'next': 0.35; 'could': 0.35; 'quite': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'framework': 0.36; 'monday,': 0.36; 'url:non-standard http port': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'suggestion': 0.37; 'things': 0.38; 'someone': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'why': 0.39; 'sure': 0.39; 'url:en': 0.39; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'group,': 0.60; 'url:3': 0.60; 'your': 0.60; 'telling': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'url:user': 0.63; 'url:0': 0.63; 'kindly': 0.64; '20,': 0.66; 'here': 0.66; 'dear': 0.67; 'expert': 0.70; 'sir,': 0.79; '(your': 0.84; '127.0.0.1': 0.84; 'url:readthedocs': 0.84; 'utc+5:30,': 0.84; '(ii)': 0.91; 'esteemed': 0.91; 'url:latest': 0.91; 'urls,': 0.91; 'received:2': 0.93; 'sitting': 0.93; 'you...': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Simmo Subject: Re: File Upload in Restful Flask Date: Mon, 20 Jul 2015 14:08:40 +0100 References: <272103ac-dd95-439f-8e1e-77d36494fc09@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 2.221.110.132 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <272103ac-dd95-439f-8e1e-77d36494fc09@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437397740 news.xs4all.nl 2836 [2001:888:2000:d::a6]:36391 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94232 On 20/07/2015 12:57, subhabrata.banerji@gmail.com wrote: > On Monday, July 20, 2015 at 4:40:09 PM UTC+5:30, Simmo wrote: >> On 20/07/2015 11:13, wrote: >>> Dear Group, >>> >>> I am trying to learn Rest framework through Restful Flask. >>> My initial exercises went fine with https://flask-restful.readthedocs.org/en/0.3.3/quickstart.html >>> >>> Now I want to upload file through Restful Flask. I tried to check the web for reference. >>> I got these urls, >>> (i) http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file >>> (ii) http://stackoverflow.com/questions/28982974/flask-restful-upload-image >>> (iii) http://blog.luisrei.com/articles/flaskrest.html >>> >>> But the question I am stuck with what are the things I have to change in the example of quickstart tutorial so that I may be able to upload file. Or if any one may kindly suggest with a small example. >>> >>> If any one of the esteemed members may kindly suggest. >>> >>> Regards, >>> Subhabrata Banerjee. >>> >> >> I'm no expert on Python or REST but the example >> >> >>> url = 'http://httpbin.org/post' >> >>> files = {'file': open('report.xls', 'rb')} >> >> >>> r = requests.post(url, files=files) >> >>> r.text >> ... >> >> seems quite straightforward so I would suggest substituting your URL for >> 'http://httpbin.org' and your file name (possibly with full pathname) >> for 'report.xls'. >> >> Give it a try and report back... >> >> Steve S > > Dear Sir, > > Thanks. I could change the quickstart api.py slightly. I ran your suggestion > on it. Some result seems coming but I may have to improve some portion, I am not getting. Please see the same. > >>>> import requests >>>> url='http://127.0.0.1:5000/toworks/post' >>>> files = {'file': open('C:\Python27\NEWS.txt', 'rb')} >>>> r = requests.post(url, files=files) >>>> r.text > u'{\n "message": "Method Not Allowed", \n "status": 405\n}\n' >>>> > > Regards, > Subhabrata Banerji > OK, so that message is telling you that whatever server is sitting behind 127.0.0.1 is not allowing you (your code) to POST to it. There are many reasons why this could be happening. Here are a couple for you to investigate... - port 5000 is not not 'open' for POSTs - your code may not have permission to POST to the server It would help if you could tell us what OS you are using (Windows or Linux or ...) and what server is sitting behind 127.0.0.1. I'n not going to be around for the next 24hrs but I'm sure someone else on the list will have some suggestions for you... Happy bug hunting Steve