Re: [web2py] Digest for web2py@googlegroups.com - 3 updates in 2 topics

52 views
Skip to first unread message

Donald McClymont

unread,
Feb 7, 2024, 1:30:16 PMFeb 7
to web...@googlegroups.com
Moving web2py from py2 to py3 should be very straightforward.  What may or may not be straightforward is moving your web2py applications from py2 to py3 as that depends a fair bit on how they have been written and certainly encoding and changes to string handling between py2 and py3 could need some work.  However py2 is well beyond it’s sell by date so it would seem appropriate to move to a relatively recent py3 version if possible.

Regards
Donald

Sent from my iPad

On 6 Feb 2024, at 20:44, web...@googlegroups.com wrote:


apinho <jaap...@sapo.pt>: Feb 06 12:09PM -0800

Hi,
 
I was using an web2py app on :
Windows Server 2016
2.18.2-stable+timestamp.2019.02.26.06.11.06
(Running on Rocket 1.2.6, Python 2.7.9)
 
Now, I'm using :
Centos 7
2.27.1-stable+timestamp.2023.11.15.23.33.20
(Running on Unknown, Python 2.7.5)
 
I'm having lots of encode problems.
 
Take this sample code :
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
def myFunction():
my_unicode = 'Eusébio'
my_goals = db.executesql("SELECT * FROM goals WHERE scorer =
'{}';".format(my_unicode), as_dict = True)
return dict(my_goals)
 
Calling /myapp/test/myFunction works fine on my Windows machine, but fails
on Centos 7 :
Traceback (most recent call last):
File "<obfuscated>/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File " <obfuscated> /web2py/applications/ <obfuscated> /controllers/test.py",
line 7, in <module>
File " <obfuscated> /web2py/gluon/globals.py", line 463, in <lambda>
self._caller = lambda f: f()
File " <obfuscated> /web2py/applications/ <obfuscated> /controllers/test.py",
line 5, in myFunction
my_goals = db.executesql("SELECT * FROM goals WHERE scorer =
'{}';".format(my_unicode), as_dict = True)
File " <obfuscated> /web2py/gluon/packages/dal/pydal/base.py", line 882,
in executesql
adapter.execute(query)
File " <obfuscated> /web2py/gluon/packages/dal/pydal/adapters/__init__.py",
line 70, in wrap
return f(*args, **kwargs)
File " <obfuscated> /web2py/gluon/packages/dal/pydal/adapters/mssql.py",
line 128, in execute
args[0] = to_unicode(args[0])
File " <obfuscated> /web2py/gluon/packages/dal/pydal/_compat.py", line
173, in to_unicode
return obj.decode(charset, errors)
File "/usr/lib64/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 39: ordinal not in range(128)
 
I'm now considering installing Python3 (Check my other post : Shell.py,
unqualified exec is not allowed), or would it be safer to stay with
Python2.7.5 and just install an older version of web2py ?
 
Can you help explain this error to me ?
 
Alexandre
Massimiliano <mbel...@gmail.com>: Feb 06 06:25PM +0100

Take a look to pyenv or nix to install a python version apart from the
system
 
 
--
Massimiliano
apinho <jaap...@sapo.pt>: Feb 06 11:40AM -0800

Hi,
 
Thank you.
 
I was under the impression that web2py was only compatible with Python2.7,
and that py4web was for Python3x.
I now understand that py2web has been modified and is also compatible with
Python3, up to 3.11.
 
That definitely opens new horizons for me. I might try to install Python3
alongside, and use it's venv.
I think that might be less confusing than trying to install a newer
Python2.7 version, on this system, do you agree ?
 
Is migrating an web2py from Python2.7 to Python 3x a straightforward task ?
Or might it need some code refactoring ?
 
Alexandre
 
On Tuesday 6 February 2024 at 17:25:31 UTC Massimiliano wrote:
 
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to web2py+un...@googlegroups.com.

apinho

unread,
Feb 8, 2024, 8:25:31 AMFeb 8
to web2py-users
Ok, thank you, a lot. I'll do as you recommend.
Alexandre
Reply all
Reply to author
Forward
0 new messages