File Upload in Restful Flask

Simmo steve at
Mon Jul 20 15:08:40 CEST 2015

On 20/07/2015 12:57, subhabrata.banerji at 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
>>> Now I want to upload file through Restful Flask. I tried to check the web for reference.
>>> I got these urls,
>>> (i)
>>> (ii)
>>> (iii)
>>> 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 = ''
>> 	>>> files = {'file': open('report.xls', 'rb')}
>> 	>>> r =, files=files)
>> 	>>> r.text
>>           ...
>> seems quite straightforward so I would suggest substituting your URL for
>> '' 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 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=''
>>>> files = {'file': open('C:\Python27\NEWS.txt', 'rb')}
>>>> r =, 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 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

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


More information about the Python-list mailing list