-1

Sorry if this is obvious. I'm a total novice and don't understand much of the language used on the forum. I'm trying to convert from Python 2.5 to 2.7 but am getting the above error message. I've simply changed the app.yaml file to show python27, changed "main.py" to read "main.app" and added "2" to the word webapp within the main.py file. Any help would be much appreciated. main.py file:

import webapp2

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))

def main ():
  application = webapp2.WSGIApplication ([('/(.*html)?', MainHandler)], 
debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()

app.yaml file:

runtime: python27
api_version: 1
threadsafe: true

handlers:
 - url: /(.*\.(gif|png|jpg|ico|js|css))
  static_files: \1
  upload: (.*\.(gif|png|jpg|ico|js|css))

- url: .*
  script: main.app
Peter C-S
  • 1
  • 1
  • Possible duplicate of [How to use Python main() function in GAE (Google App Engine)?](https://stackoverflow.com/questions/40085542/how-to-use-python-main-function-in-gae-google-app-engine) – Dan Cornilescu Jun 07 '17 at 03:39

1 Answers1

0

when you write "main.app" python is looking for main.py, and inside looks for "app", that's why you're getting the error

keep the filename main.py, and when you import it anywhere simply refer to it as "main" (without .py)

now if what you want to run is main() inside of the main.py file, that should look like main.main

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62
  • Much appreciated. Sorry, not quite with you. Which part of the code should I change? – Peter C-S Jun 03 '17 at 13:54
  • i can only repeat what i said - you changed your "main.py" file to "main.app", don't do that, change it back. and whenever you refer to it in your code, you should probably write "main" without writing ".py" within the code itself – Ofer Sadan Jun 03 '17 at 19:16
  • Thanks. I've not changed the name or extension of my main.py file, that remains main.py. I changed the line in app.yaml that previously read "main.py" to read "main.app". I've changed this line to simply "main" and now have this message: Traceback (most recent call last): File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle result = handler(dict(self._environ), self._StartResponse) TypeError: 'module' object is not callable – Peter C-S Jun 05 '17 at 09:57
  • oh ok now we're getting somewhere... it has located the module "main" but is trying to "call" it and obviously can't. I'm guessing you are attempting to run the `main()` function withing that, so change that line again to `main.main` – Ofer Sadan Jun 05 '17 at 10:02
  • Ok - have done that. Thanks. Error now reads: TypeError: main() takes no arguments (2 given) – Peter C-S Jun 05 '17 at 10:25
  • you're original question was about the module and the import error, and that is now solved, but sadly i don't know enough to help you further.... i think you should close this question and start a new question about that new error – Ofer Sadan Jun 05 '17 at 10:36