2

I am trying to run bottle py but getting this error:

Traceback (most recent call last):
  File "/home/pi/Desktop/gggg.py", line 176, in <module>
    run(host='somehost', port=81)
  File "/usr/lib/python2.7/dist-packages/bottle.py", line 2426, in run
    server.run(app)
  File "/usr/lib/python2.7/dist-packages/bottle.py", line 2123, in run
    srv = make_server(self.host, self.port, handler, **self.options)
  File "/usr/lib/python2.7/wsgiref/simple_server.py", line 144, in make_server
    server = server_class((host, port), handler_class)
  File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/wsgiref/simple_server.py", line 48, in server_bind
    HTTPServer.server_bind(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 13] Permission denied
>>> 

I am logged in as "pi". Logging in as root user solves the issue. My question is what permissions does the bottle py and python need to run (which folders and what permissions)?

Edit:

Not sure if it matters but my python files are in Desktop dir. I also set the permissions of the folder/sub-folder to read write for all.

DominicM
  • 6,520
  • 13
  • 39
  • 60
  • 2
    related: http://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-1024-on-l – Wooble Aug 09 '13 at 17:40
  • Doesn't really seem related, it's not development only system so I just want to change the required permissions. – DominicM Aug 09 '13 at 17:44
  • 1
    You want to use a port less than 1024, and you don't want to be root. Seems related to me. *shrug* – Wooble Aug 09 '13 at 17:45
  • Didn't think it was related to the port, will look into it more, thanks. – DominicM Aug 09 '13 at 17:47

2 Answers2

3

1) If you're planning on running this in production, you shouldn't be using Bottle's built in web server. You should use Apache, nginx, etc. From the Bottle docs:

The built-in default server is based on wsgiref WSGIServer. This non-threading HTTP server is perfectly fine for development and early production, but may become a performance bottleneck when server load increases. There are three ways to eliminate this bottleneck:

  • Use a different server that is either multi-threaded or asynchronous.
  • Start multiple server processes and spread the load with a load-balancer.
  • Do both.

2) [As you know,] You have to be root to bind to port 80; no way around that. Have you considered using sudo?

sudo /home/pi/Desktop/gggg.py

You could configure sudoers to securely allow user "pi" to execute only gggg.py (or whatever webserver you'll end up using for production).

ron rothman
  • 17,348
  • 7
  • 41
  • 43
  • Production use will be single user so I don't think it's worth using apache. I might move from Bottle to something like WebPy later though. Sudo sounds like a good solution, I didn't think of that but since it will run as a cron job it woun't annoy me and for development port over 1024 works fine, thanks. – DominicM Aug 09 '13 at 21:42
  • Cool, happy to help. Yeah, if your app is single-user and has low volume (and doesn't need any other features of a full web server), then your plan sounds good. Cheers. – ron rothman Aug 09 '13 at 21:53
2

Thanks to @Wooble I realised that permission error had to do with the port and not the file system.

A working workaround is to use port above 1024 which works perfectly and is fine for development. Using port 200 for now:

run(host='someIP', port=2000)

I am still looking for a port 80 permission error solution though.

DominicM
  • 6,520
  • 13
  • 39
  • 60