Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running some Python code which uses urllib2.urlopen which works fine when run as the user, root (Linux).

However, it doesn't work when run as user apache (we're running it through apache version 1) - I get this error:

Traceback (most recent call last):
  File "/srv/www/vm/custom/", line 118, in ?
    a = confirm_paypal(f, f1)
  File "/srv/www/vm/custom/", line 47, in confirm_paypal
    response = urllib2.urlopen(PP_URL, params)
  File "/usr/lib64/python2.4/", line 130, in urlopen
    return, data)
  File "/usr/lib64/python2.4/", line 358, in open
    response = self._open(req, data)
  File "/usr/lib64/python2.4/", line 376, in _open
    '_open', req)
  File "/usr/lib64/python2.4/", line 337, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.4/", line 1040, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib64/python2.4/", line 1006, in do_open
    raise URLError(err)
URLError: <urlopen error (13, 'Permission denied')>

Is there a way to give the user, apache, access to this function?

Update 1

Running Python 2.4.3 and Apache 2.2.3

share|improve this question

I am not sure what the answer is, but I think I would try trouble shooting it like this.

Use su to change into the apache users context, and then run the python script with strace. I would guess that it is trying to access a file or create a temporary file or something somewhere.

If I was to make a wild guess I would see that it appears like you are trying to use https. Perhaps it is trying to load the CA certificates and doesn't have access?

It doesn't run as the apache user, will your python script run as a different non-root user?

share|improve this answer
Ah, ok, when using su apache, the script runs fine. The problem seems to occur when it's invoked through the apache server (running as apache user). – nbolton Sep 15 '09 at 1:42
I would look for differences in the environment. Check to see that PATH and TMP are the same. Check that apache is using the same version of python. Since the script runs for you, it sure seems like it should be working. – Zoredache Sep 15 '09 at 6:15
Hmm, TMP isn't defined in either environments. And the two PATH values are slightly different - but can't spot anything wrong per say. Both Apache and the terminal are using the same versions of Python. I think it's a case of reconfiguring Apache, but can't think what. – nbolton Sep 15 '09 at 16:45
up vote 1 down vote accepted

Turns out SELinux was stopping apache from using ports; after turning SELinux off, the problem went away.

share|improve this answer
Just had this issue. If anyone should wish to keep selinux running, the command setsebool -P httpd_can_network_relay=1 will fix this ... – EMiller Sep 1 '10 at 20:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.