1

import webapp2 is throwing exception error --> Traceback (most recent call last):

File "/homefolder/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 5, in import webapp2

File "//anaconda3/lib/python3.7/site-packages/webapp2.py", line 571

except Exception, e:
                    ^
SyntaxError: invalid syntax

I found a related post, but that seems like an old post without recent updates.

webapp2 with python3.

Can someone please advise ?

Gourav Joshi
  • 2,419
  • 2
  • 27
  • 45
TOI 700 e
  • 197
  • 1
  • 3
  • 18

2 Answers2

2

That is perfectly valid python2 syntax:

$ python
Python 2.7.12 (default, Jul 01 2016, 15:36:53) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> try:
...  os.listdir('.')
... except Exception, e:
...  pass
... 
['2018', '2015', '2017', '2016', '2019']

But, as you observed, the syntax is invalid in python3. So things didn't change since the post you referenced, webapp2 remains compatible with python2 only.

As a general approach the GAE team moved towards dropping altogether many of the GAE-specific libraries and frameworks instead of porting them to newer language versions (not only python!). Instead they lowered the sandbox restrictions allowing more 3rd party such libraries and frameworks to be used instead, see Why is Google App Engine Standard using PHP 5.5?

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
1

As noted in Dan's answer, webapp2 is only compatible with python2. In the long run, I am going to migrate to Flask; but in the short term, I'm also trying to migrate away from dev_appserver and python 2.7 and a few other things, and I really want to limit the number of things I have to change at the same time.

So with that said - you should check out webapp3, which I am using as a nice little bridging solution: https://pypi.org/project/webapp3/

penitent_tangent
  • 762
  • 2
  • 8
  • 18