Reputation: 877
Im trying to create a website with Web.py but its not letting me open a create a socket on port 80 but it works on every other port.
I have port forwarded and all that so that's not the problem.
python main.py 80
but when I do this I get the error:
http://0.0.0.0:80/
Traceback (most recent call last):
File "main.py", line 43, in <module>
app.run()
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 311, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "/usr/local/lib/python2.7/dist-packages/web/wsgi.py", line 54, in runwsgi
return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
File "/usr/local/lib/python2.7/dist-packages/web/httpserver.py", line 148, in runsimple
server.start()
File "/usr/local/lib/python2.7/dist-packages/web/wsgiserver/__init__.py", line 1753, in start
raise socket.error(msg)
socket.error: No socket could be created
my code so far is:
import MySQLdb
import web
import hashlib as h
urls = (
'/', "index", "/register/?", "register", "/login/?", "login", "/thankyou/?", "thankyou"
)
app = web.application(urls, globals())
render = web.template.render("templates/")
db = web.database (dbn="mysql", user="root", pw="461408", db="realmd")
class index():
def GET(self):
return render.index()
class register():
def GET(self):
return render.register()
def POST(self):
i = web.input()
user = h.sha1(i.username).hexdigest()
pw = h.sha1(i.password).hexdigest()
n = db.insert("account", username=user, password=pw)
if __name__ == '__main__':
app.run()
Can someone help please?
Upvotes: 6
Views: 19323
Reputation: 15770
Could it be the fact you're trying to launch web.py as an unprivileged user?
try:
sudo python ./bin/blah.py
Upvotes: 1
Reputation: 329
I successfully start the service by using this command in port 80
sudo python index.py 80
but when I use the shortcut key (control+c) to close the service,there will be an error.
^CTraceback (most recent call last):
File "application.py", line 206, in <module>
app.run()
File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 313, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgi.py", line 54, in runwsgi
return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 159, in runsimple
server.stop()
File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1932, in stop
self.requests.stop(self.shutdown_timeout)
File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1471, in stop
worker.join(remaining_time)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 680, in join
self.__block.release()
thread.error: release unlocked lock
^C^CException KeyboardInterrupt in <module 'threading' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyc'> ignored
When it happens, I Kill All Python Processes...
killall -9 python
it's can solve the above problems, but not recommended
Upvotes: 6
Reputation: 19
I ran into the same problem on my RaspberryPi. To fix I just added sudo before the command. Try: sudo python main.py 80
Upvotes: 1
Reputation: 17535
Visit 127.0.0.1
in a browser. There is likely already a process using port 80, and that port is supposed to be used for http, so that's probably the easiest way to see what's using it.
Upvotes: 4
Reputation: 363486
You possibly have something else working on port 80. Try the command netstat -ln | grep 80
to check that.
Alternatively, you can try telnet localhost 80
, and if the connection is refused then that port should be clear to use.
Upvotes: 12