Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94225 > unrolled thread

File Upload in Restful Flask

Started bysubhabrata.banerji@gmail.com
First post2015-07-20 03:13 -0700
Last post2015-07-20 06:47 -0700
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  File Upload in Restful Flask subhabrata.banerji@gmail.com - 2015-07-20 03:13 -0700
    Re: File Upload in Restful Flask Simmo <steve@bellissimmo.com> - 2015-07-20 12:09 +0100
      Re: File Upload in Restful Flask subhabrata.banerji@gmail.com - 2015-07-20 04:57 -0700
        Re: File Upload in Restful Flask Simmo <steve@bellissimmo.com> - 2015-07-20 14:08 +0100
          Re: File Upload in Restful Flask subhabrata.banerji@gmail.com - 2015-07-20 06:47 -0700

#94225 — File Upload in Restful Flask

Fromsubhabrata.banerji@gmail.com
Date2015-07-20 03:13 -0700
SubjectFile Upload in Restful Flask
Message-ID<c213a890-0e01-43dd-9cd4-e0dcba3c196f@googlegroups.com>
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. 

[toc] | [next] | [standalone]


#94228

FromSimmo <steve@bellissimmo.com>
Date2015-07-20 12:09 +0100
Message-ID<mailman.782.1437390589.3674.python-list@python.org>
In reply to#94225
On 20/07/2015 11:13, subhabrata.banerji@gmail.com 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

[toc] | [prev] | [next] | [standalone]


#94230

Fromsubhabrata.banerji@gmail.com
Date2015-07-20 04:57 -0700
Message-ID<272103ac-dd95-439f-8e1e-77d36494fc09@googlegroups.com>
In reply to#94228
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

[toc] | [prev] | [next] | [standalone]


#94232

FromSimmo <steve@bellissimmo.com>
Date2015-07-20 14:08 +0100
Message-ID<mailman.786.1437397740.3674.python-list@python.org>
In reply to#94230
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

[toc] | [prev] | [next] | [standalone]


#94234

Fromsubhabrata.banerji@gmail.com
Date2015-07-20 06:47 -0700
Message-ID<582a8fb9-77c6-4173-aa9e-f4e9c24885f2@googlegroups.com>
In reply to#94232
On Monday, July 20, 2015 at 6:39:29 PM UTC+5:30, Simmo wrote:
> On 20/07/2015 12:57, 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

Dear Sir,

Thanks. I am on MS-Windows 7 and I use mostly Firefox. I am checking other issues.

Regards,
Subhabrata Banerjee. 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web