Hi I have tried Python TCPIP sockets and Unix sockets processed in a python cgi 
script, called from apache under fedora19. In both cases a permissions error is 
returned at sock.connect(). I have tried changing permissions x and r w on ALL 
of user, group, other to no avail. In both cases the cgi script runs if 
directly executed from /var/www/cgi-bin with no apache involvement.

  In both cases all the other (non sockets())  python cgi scripting works in 
the apache server environment. 

  I note I needed to enable http in the ferora19 firewall to have the apache 
server work from locahost or from another device connected to the router. 
Please find the myUnix2.cgi socket script below. Help appreciated! Regards,     
         Stewart Lawton
#!/usr/bin/envpython
import cgi
import socket
import sys
defhtmlTop():
 print("""Content-type:text/html\n\n
 <DOCTYPEhtml>
 <html lang="en">
  <head>
       <metacharset="utf-8" />
      <title> MyServer Template </title>
      </head>
      <body>""")
 
defhtmlTail():
 print("""<body/>
      </html> """   )

defcreSockettoServer():
# Create a TCP/IP socket
   sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
   server_address ='../../.././home/johnlawton/workspace/myUnixSock/uds_socket'
   try:
     sock.connect(server_address)
   except socket.error,msg:
     print>>sys.stderr, msg
     sys.exit(1)
#Send data
    message = 'This is the message. It will be repeated.'
#   print >>sys.stderr,'sending "%s"' % message
   sock.sendall(message)
    return

#mainprogram
if __name__ == "__main__":
   try:
        htmlTop()
       creSockettoServer()
       print("Hello World from my Unix2 cgi Script ")
       
        htmlTail()
   except:
       cgi.print_exception()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to