Exception while handling exception at gluon/streamer.py (python 3)

37 views
Skip to first unread message

Antonio Salazar

unread,
Apr 18, 2018, 1:00:43 PM4/18/18
to web2py-users
Now that web2py supports python 3, I just went on and migrated my website. All works fine, except for a crash which I'm not sure how to handle.

I get this when the browser looks for /favicon.ico (a non-existent file because it's in /images/favicon.ico)
Traceback (most recent call last):
 
File "R:\Website Extranet\Fuentes\web2py\gluon\main.py", line 329, in wsgibase
    response
.stream(static_file, request=request)
 
File "R:\Website Extranet\Fuentes\web2py\gluon\globals.py", line 617, in stream
    status
=self.status)
 
File "R:\Website Extranet\Fuentes\web2py\gluon\streamer.py", line 66, in stream_file_or_304_or_206
   
if e[0] == errno.EISDIR:
TypeError: 'FileNotFoundError' object is not subscriptable

The problem is the handling of exceptions in base/streamer.py
except IOError as e:
   
if e[0] == errno.EISDIR:
       
raise HTTP(403, error_message, web2py_error='file is a directory')
   
elif e[0] == errno.EACCES:
       
raise HTTP(403, error_message, web2py_error='inaccessible file')
   
else:
     
raise HTTP(404, error_message, web2py_error='invalid file')


e[0] crashes because e is not indexable, it expects e.errno instead.

Antonio Salazar

unread,
Apr 18, 2018, 5:04:57 PM4/18/18
to web2py-users
The bug is very easy to reproduce:

It seems only base/streamer.py and contrib/gateways/fcgi.py handle exceptions in this way.

Antonio Salazar

unread,
Apr 19, 2018, 1:50:52 PM4/19/18
to web2py-users
Is anyone running into this issue? It's happening both in Windows and Linux.
Should I postpone migrating to python3?

Carlos Cesar Caballero Díaz

unread,
Apr 19, 2018, 2:42:31 PM4/19/18
to web...@googlegroups.com

With Python 3 there are definitely issues with the error traces. Sometimes is difficult to find what is failing.

Greetings.


El 19/04/18 a las 13:50, Antonio Salazar escribió:
Is anyone running into this issue? It's happening both in Windows and Linux.
Should I postpone migrating to python3?

On Wednesday, April 18, 2018 at 4:04:57 PM UTC-5, Antonio Salazar wrote:
The bug is very easy to reproduce:
  • Clone the repository from GitHub
  • Run python3 web2py.py

It seems only base/streamer.py and contrib/gateways/fcgi.py handle exceptions in this way.


On Wednesday, April 18, 2018 at 12:00:43 PM UTC-5, Antonio Salazar wrote:
Now that web2py supports python 3, I just went on and migrated my website. All works fine, except for a crash which I'm not sure how to handle.

I get this when the browser looks for /favicon.ico (a non-existent file because it's in /images/favicon.ico)
Traceback (most recent call last):
 
File "R:\Website Extranet\Fuentes\web2py\gluon\main.py", line 329, in wsgibase
    response
.stream(static_file, request=request)
 
File "R:\Website Extranet\Fuentes\web2py\gluon\globals.py", line 617, in stream
    status
=self.status)
 
File "R:\Website Extranet\Fuentes\web2py\gluon\streamer.py", line 66, in stream_file_or_304_or_206
   
if e[0] == errno.EISDIR:
TypeError: 'FileNotFoundError' object is not subscriptable

The problem is the handling of exceptions in base/streamer.py
except IOError as e:
   
if e[0] == errno.EISDIR:
       
raise HTTP(403, error_message, web2py_error='file is a directory')
   
elif e[0] == errno.EACCES:
       
raise HTTP(403, error_message, web2py_error='inaccessible file')
   
else:
     
raise HTTP(404, error_message, web2py_error='invalid file')


e[0] crashes because e is not indexable, it expects e.errno instead.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Salazar

unread,
Apr 19, 2018, 5:13:02 PM4/19/18
to web2py-users
This exception is quite clear, though.
I decided to create an issue in the git repository, since this is a showstopper if you want to use web2py with python 3.
Reply all
Reply to author
Forward
0 new messages