简体   繁体   中英

python script not running with web.py

I am new to Python and am trying to run a very simple Python script on a web page, using the tutorial on web.py . When I installed web.py through the terminal it said it installed successfully, but when I try to run hello.py I get the following error messages (screenshot and text below), and nothing opens on my localhost. error message

----------------------
CODE FROM WEB.PY
----------------------

import web

urls = (
  '/', 'hello')

app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, web!'

if __name__ == "__main__":
    app.run()

ERROR MESSAGE

The above is a description of an error in a Python program, formatted for a Web browser because the 'cgitb' module was enabled. In case you are not reading this in a Web browser, here is the original traceback:

Traceback (most recent call last): File "hello.py", line 1, in <module> import web File "/Users/swanstro/Desktop/web/ init .py", line 14, in <module> import utils, db, net, wsgi, http, webapi, httpserver, debugerror File "/Users/swanstro/Desktop/web/wsgi.py", line 8, in <module> import http File "/Users/swanstro/Desktop/web/http.py", line 16, in <module> import net, utils, webapi as web File "/Users/swanstro/Desktop/web/webapi.py", line 31, in <module> import sys, cgi, Cookie, pprint, urlparse, urllib File "/Users/swanstro/Desktop/cgi.py", line 22, in <module> form = cgi.FieldStorage() AttributeError: 'module' object has no attribute 'FieldStorage'

Any help would be welcome. Thanks.

It looks like you have a file named cgi.py (/Users/swanstro/Desktop/cgi.py) that is conflicting with the Python standard library cgi module when you try to import cgi . Try renaming cgi.py to something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM