Skip to content
Advertisement

Why does python xmlrpc call get PermissionError when run through apache?

Here’s /home/blakeh/test.py, which doesn’t really do anything but illustrate the problem with minimal code:

#!/usr/local/bin/python3
import xmlrpc.client
if __name__ == "__main__":
    client = xmlrpc.client.ServerProxy('http://localhost:8010')
    client.foo()

If I run this directly as the apache user, there’s no permission problem with making the RPC “foo” call. It only occurs if I run it through apache. I’m using python 3.5.2.

In an apache .conf file I have this:

ScriptAlias /test "/home/blakeh/test.py"

If I run this curl command:

curl -gix "" http://localhost/test

… I get an internal server error, with this appended to /var/log/httpd/error_log:

[Wed Jan 04 21:23:09 2017] [error] [client ::1] Traceback (most recent call last):
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/home/blakeh/test.py", line 7, in <module>
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     client.foo()
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1092, in __call__
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     return self.__send(self.__name, args)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1432, in __request
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     verbose=self.__verbose
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1134, in request
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     return self.single_request(host, handler, request_body, verbose)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1146, in single_request
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     http_conn = self.send_request(host, handler, request_body, verbose)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1259, in send_request
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     self.send_content(connection, request_body)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1289, in send_content
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     connection.endheaders(request_body)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/http/client.py", line 1102, in endheaders
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     self._send_output(message_body)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/http/client.py", line 934, in _send_output
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     self.send(msg)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/http/client.py", line 877, in send
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     self.connect()
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/http/client.py", line 849, in connect
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     (self.host,self.port), self.timeout, self.source_address)
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/socket.py", line 711, in create_connection
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     raise err
[Wed Jan 04 21:23:09 2017] [error] [client ::1]   File "/usr/local/lib/python3.5/socket.py", line 702, in create_connection
[Wed Jan 04 21:23:09 2017] [error] [client ::1]     sock.connect(sa)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] PermissionError: [Errno 13] Permission denied

What could explain the difference in behavior? Thanks!

Advertisement

Answer

Velkan’s suggestion to check selinux worked. I could get this working by putting it in permissive mode with “setenforce 0”. Adding this as an “answer” so I can mark it as solved.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement