[web2py] Re: File Download Broken after Pull Request #2471

2023-10-26 Thread CarlosDB
Yes, for me it works fine now.

Thanks.
Carlos.


El jueves, 26 de octubre de 2023 a las 7:42:25 UTC+2, Massimo Di Pierro 
escribió:

> I agree with you. I committed your proposed change to master. Please 
> confirm this indeed fixes it and I will make another release.
>
> On Wednesday, 4 October 2023 at 08:26:46 UTC-7 CarlosDB wrote:
>
>> Hello,
>>
>> Today, I downloaded web2py from GitHub to start testing a future update. 
>> I have several "upload" fields for images, and they have all started to 
>> fail.
>>
>> After some investigation, I found that this issue started after Pull 
>> Request (PR) #2471 (Sanitize Headers) was merged. Link to PR 
>> .
>>  
>> This PR modifies the file gluon/http.py.
>>
>> The following code:
>> @cache.action(time_expire=86400)
>> def download():
>> return response.download(request, db)
>>
>> has stopped working.
>>
>> If I remove the line "@cache.action(time_expire=86400)", it works, but 
>> that's not a good solution.
>>
>> While investigating the root of the problem, I found the issue around 
>> line 123 of gluon/http.py. It used to be like this:
>>
>> rheaders = []
>> for k, v in iteritems(headers):
>> if isinstance(v, list):
>> rheaders += [(k, item) for item in v]
>> else:
>> rheaders.append((k, v))
>> responder(status, rheaders)
>>
>> Now it looks like this:
>>
>> rheaders = []
>> for k, v in iteritems(headers):
>> if isinstance(v, list):
>> rheaders += [(k, str(item)) for item in v]
>> elif v is not None:
>> rheaders.append((k, str(v)))
>> responder(status, rheaders)
>>
>>
>> The variable "rheaders" contains the HTTP headers, but with these 
>> modifications, some values are int or None, but they should be str. For 
>> example:
>> ('Content-Length', 29563)
>> ('Pragma', None)
>>
>> ('Content-Length', 29563) should be ('Content-Length', '29563'), and I 
>> believe ('Pragma', None) is a deprecated header that should be removed.
>>
>> A possible solution could be to revert part of the PR, but I think there 
>> might be a better solution.
>>
>> The real issue seems to originate from the files gluon/streamer.py and 
>> gluon/cache.py. I have commented on the lines that have problems:
>>
>> *In gluon/streamer.py, line 127*:
>>
>> # in all the other cases (not 304, not 206, but 200 or error 
>> page)
>> if status != 206:
>> enc = request.env.http_accept_encoding
>> if enc and 'gzip' in enc and not 'Content-Encoding' in headers:
>> gzipped = static_file + '.gz'
>> if os.path.isfile(gzipped) and os.path.getmtime(gzipped) >= 
>> modified:
>> static_file = gzipped
>> fsize = os.path.getsize(gzipped)
>> headers['Content-Encoding'] = 'gzip'
>> headers['Vary'] = 'Accept-Encoding'
>> try:
>> stream = open(static_file, 'rb')
>> except IOError as e:
>> # this better not happen when returning an error page ;-)
>> if e.errno in (errno.EISDIR, errno.EACCES):
>> raise HTTP(403)
>> else:
>> raise HTTP(404)
>> headers['Content-Length'] = fsize   # should be: 
>> headers['Content-Length'] = str(fsize)
>>
>> *In gluon/cache.py, line 676:*
>>
>> if send_headers:
>> headers = {'Pragma': None,  # Deprecated: This 
>> feature is no longer recommended
>>'Expires': expires,
>>'Cache-Control': cache_control}
>>
>>
>> What is your opinion?
>> Best way to solve it? 
>>
>> Carlos.
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ad0042e2-2bb2-4682-bfe7-1c97a2daefd3n%40googlegroups.com.


Re: [web2py] Re: AssertionError: Header names/values must be of type str

2023-10-26 Thread Massimo DiPierro
Can you try once more?

On Wed, 25 Oct 2023 at 23:03, Al Ex  wrote:

> I tried with a new installation of web2py
>
> $ git clone --recursive https://github.com/web2py/web2py.git
>
>
> It gives the same error
>
> *
> ERROR:Rocket.Errors.Thread-11:Traceback (most recent call last):
>
>   File "/Users/z/Documents/web2py/gluon/rocket.py", line 1347, in run
> self.run_app(conn)
>
>   File "/Users/z/Documents/web2py/gluon/rocket.py", line 1865, in run_app
> output = self.app(environ, self.start_response)
>
>   File "/Users/z/Documents/web2py/gluon/main.py", line 688, in
> app_with_logging
> ret[0] = wsgiapp(environ, responder2)
>
>   File "/Users/z/Documents/web2py/gluon/main.py", line 600, in wsgibase
> return http_response.to(responder, env=env)
>
>   File "/Users/z/Documents/web2py/gluon/http.py", line 127, in to
> responder(status, rheaders)
>
>   File "/Users/z/Documents/web2py/gluon/main.py", line 683, in responder2
> return responder(s, h)
>
>   File "/Users/z/Documents/web2py/gluon/rocket.py", line 1827, in
> start_response
> self.header_set = Headers(response_headers)
>
>   File
> "/Users/z/.pyenv/versions/3.10.2/lib/python3.10/wsgiref/headers.py", line
> 39, in __init__
> self._convert_string_type(v)
>
>   File
> "/Users/z/.pyenv/versions/3.10.2/lib/python3.10/wsgiref/headers.py", line
> 45, in _convert_string_type
> raise AssertionError("Header names/values must be"
>
> AssertionError: Header names/values must be of type str (got 50)
>
> On October 26, 2023 at 14:43:28, Massimo Di Pierro (
> massimo.dipie...@gmail.com) wrote:
>
> I believe this is now fixed in master, thanks to Carlos' suggestion. Can
> you please give it a try?
>
> On Monday, 23 October 2023 at 13:30:34 UTC-7 alex wrote:
>
>> Hi, Running web2py in virtualenviroment (python 3.9.5, it happens also in
>> python 3.10.10)
>>
>> 
>>
>> ERROR:Rocket.Errors.Thread-3:Traceback (most recent call last):
>>
>>   File "/Users/z/dev/web2py/gluon/rocket.py", line 1294, in run
>> self.run_app(conn)
>>
>>   File "/Users/z/dev/web2py/gluon/rocket.py", line 1796, in run_app
>> output = self.app(environ, self.start_response)
>>
>>   File "/Users/z/dev/web2py/gluon/main.py", line 648, in app_with_logging
>> ret[0] = wsgiapp(environ, responder2)
>>
>>   File "/Users/z/dev/web2py/gluon/main.py", line 562, in wsgibase
>> return http_response.to(responder, env=env)
>>
>>   File "/Users/z/dev/web2py/gluon/http.py", line 129, in to
>> responder(status, rheaders)
>>
>>   File "/Users/z/dev/web2py/gluon/main.py", line 643, in responder2
>> return responder(s, h)
>>
>>   File "/Users/z/dev/web2py/gluon/rocket.py", line 1759, in start_response
>> self.header_set = Headers(response_headers)
>>
>>   File "/Users/z/.pyenv/versions/3.9.5/lib/python3.9/wsgiref/headers.py",
>> line 39, in __init__
>> self._convert_string_type(v)
>>
>>   File "/Users/z/.pyenv/versions/3.9.5/lib/python3.9/wsgiref/headers.py",
>> line 45, in _convert_string_type
>> raise AssertionError("Header names/values must be"
>>
>> AssertionError: Header names/values must be of type str (got 50)
>>
>> 
>> Any hints?
>> Thank you
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/2f971066-7e75-440e-80e0-cc132afacc93n%40googlegroups.com
> 
> .
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAJYrZrmV7wEAJKRKDQq%3DMwP31%3Dv_W2qg0-zp_tGMq5_OaJdhHA%40mail.gmail.com.