How do I change permissions to a socket?

I am trying to run a simple Python based web server given here.

And I get the following error message:

Traceback (most recent call last):
  File "webserver.py", line 63, in <module>
    main()
  File "webserver.py", line 55, in main
    server = HTTPServer(('', 80), MyHandler)
  File "/usr/lib/python2.5/SocketServer.py", line 330, in __init__
    self.server_bind()
  File "/usr/lib/python2.5/BaseHTTPServer.py", line 101, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib/python2.5/SocketServer.py", line 341, in server_bind
    self.socket.bind(self.server_address)
  File "<string>", line 1, in bind
socket.error: (13, 'Permission denied')

As far as I understand my firewall blocks access to a socket? Am I right? If it is the case, how can I change the permissions? Is it dangerous to change these permissions?


Asked by: Alissa950 | Posted: 06-12-2021






Answer 1

If you want to bind to port numbers < 1024, you need to be root. It's not a firewall issue; it's enforced by the operating system. Here's a reference from w3.org, and a FAQ entry specific to Unix.

Answered by: Lenny599 | Posted: 07-01-2022



Answer 2

If you want to run on a port under 1024, you'll need to be root. You can open the socket and drop root's permission for the rest of your program by switching to another user.

Most times it's easier to run a real webserver (say nginx) on port 80 and proxy the requests through to your program which you can run on a high numbered port (8080 for example). This way you don't need to worry about screwing something up during the time your process is running as root, as it never runs as root.

If it's just for testing, run the server on port 8080 and connect at http://localhost:8080/

Answered by: Dominik917 | Posted: 07-01-2022



Similar questions

python - How to change file access permissions in linux?

How does one change file access permissions? f = open('test','w') f.close() Defaults access permissions: 10600


python - How do I change Apache permissions?

I need to web scraping (e.g. www.google.com) and show the result in another web page, but it seams apache's user does not have permission to open firefox to scrape. The project has a docker image (php-apache), a php file (that calls the scraping), and a python file, which scrapes using selenium. I'm able to execute...


python - Amazon S3 permissions

Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this?


python - Permissions for a site only

I have a multilingual Django project. Every language is a different subdomain. So we've decided to use the "sites" application and to create one different site for every language. On that project, I also have a "pages" application, which is quite similar to a CMS. The user can create pages with content and they'll be displayed in the appropriate language site. Now I'm looking to be able to manage advanced p...


python - Django - user permissions to certain views?

From the admin I see that you can allocate permissions to a user or a user group to :allow add, change or delete data from a model. That is great, but I also need to allow a user or a user group to access or not a group of views. I have certain type of services on my web site so I want to allow some users to access a certain services (pages/views) but not others. So how can I allow certain users/user group...


python - Adding permissions to django users which have add-on models

I will be creating an intranet site with multiple roles (client-employee, client-admin, staff team member). Each role will have a model that attaches (via One-to-One or ForeignKey field) to a user with custom fields. I want each role to have it's own set of permissions (like a group). How can I store this permissions set inside my application. Groups seem to be defined as part of the contrib.admin app rather than ...


python - Is there a Django app that can handle groups and permissions?

I know that Django has a permission/group system. But that's mostly tied to each model. (Correct me if I'm wrong.) My purpose is to have groups that can do multiple stuff. For example, one group can write to this and that. One group can edit this and that in different servers, different databases. Basically, it's beyond the model system. I just want a custom groups system that's not tied...


python - User permissions for Django module

I'm having a small issue with my permissions in my Django template. I'm trying to, based on permissions, show an icon in the menu bar for my project. I want to have it so that if the user has the permissions to add a new follow-up to the project, they can see the icon, if they don't have that permission, then do not display the link. My permission syntax is follow.add_followup, which I got from ...


python - How to change file access permissions in linux?

How does one change file access permissions? f = open('test','w') f.close() Defaults access permissions: 10600


python - how to launch gnome apps with su permissions?

I have a python app I want to distribute as an rpm. The app requires talking to usb devices. To talk to usb devices, I need sudo privileges (or some type of permission I've yet to learn about). Unfortunately, my app fails to launch from the gnome application menu with a .desktop file when I specify running as sudo. won't even launch EXEC=sudo python /usr/bin/app_launcher....


Permissions, Python Script

I am learning to write Python Scripts for work and I have run into some problems. The script is supposed to read a file, and print the permissions to an email. My problem is I am getting an error when it tries to call the permission() method, and I don't know how to fix it. Python Code import smtplib import os import stat result = "" def permission(file): s = os.stat(file)...


Python CGI permissions error

I can't seem to open and write to a text file from my CGI script.. I keep getting permissions errors (which I see from CGITb) Whenever I try to do this: f = open("/Users/varatis/Documents/data.txt","a+") I get this: &lt;type 'exceptions.IOError'&gt;: [Errno 13] Permission denied: '/Users/varatis/Documents/data.txt' args = (13, 'Permission denied') errno = 13 ...


zip - Set permissions on a compressed file in python

I have a file test.txt that is inside a zip archive test.zip. The permissions on test.txt are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell. EDIT: Here's what I've got so far: import zipfile z = zipfile.ZipFile('test.zip', 'w'...


python - Will Django be a good choice for a permissions based web-app?

I've been exploring the details of Django for about a week now and like what I see. However I've come upon some.. negativity in relation to fine-grained control of permissions to the CRUD interface. What I'm writing is an Intranet client management web-app. The organisation is about 6 tiers, and I need to restrict access to client groups based on tiers. Continually expanding. I have a fairly good idea how I'm going...


python - Amazon S3 permissions

Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this?


chmod - check permissions of directories in python

i want a python program that given a directory, it will return all directories within that directory that have 775 (rwxrwxr-x) permissions thanks!


python - Permissions for a site only

I have a multilingual Django project. Every language is a different subdomain. So we've decided to use the "sites" application and to create one different site for every language. On that project, I also have a "pages" application, which is quite similar to a CMS. The user can create pages with content and they'll be displayed in the appropriate language site. Now I'm looking to be able to manage advanced p...


python - DB Permissions with Django unit testing

Disclaimer: I'm very new to Django. I must say that so far I really like it. :) (now for the "but"...) But, there seems to be something I'm missing related to unit testing. I'm working on a new project with an Oracle backend. When you run the unit tests, it immediately gives a permissions error when trying to create the schema. So, I get what it's trying to do (create a clean sandbox), but what...


linux - Dropping Root Permissions In Python

I'd like to have a Python program start listening on port 80, but after that execute without root permissions. Is there a way to drop root or to get port 80 without it?


setting permissions of python module (python setup install)

I am configuring a distutils-based setup.py for a python module that is to be installed on a heterogeneous set of resources. Due to the heterogeneity, the location where the module is installed is not the same on each host however disutils picks the host-specific location. I find that the module is installed without o+rx permissions using disutils (in spite of setting umask ahead of running setup.py). One solutio...


python - Django 1.2 object level permissions - third party solutions?


python - Django Inlines user permissions + view only - permissions issues

I'm not sure if this is a bug or I'm just missing something (although I have already parsed the documentation about inlines), but: Let's say I have a model A. Model A is an inline of model B. User U has full access to model B, but only change permissions to model A (so, no add, nor delete). However, when editing model B, user U can still see the "Add another A" link at the bottom, although U hasn't add perm...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top