GROT 239: Re: [Tutor] Bug with fork / socket from CGI
Lloyd Kvam
pythontutor@venix.com
Fri Aug 1 17:08:02 2003
>>> sock.close()
Looking at the source code, error 9 comes from a closedsocket object.
class _closedsocket:
def __getattr__(self, name):
raise error(9, 'Bad file descriptor')
You can't close sock and then use it to make the connection.
Jonathan Hayward http://JonathansCorner.com wrote:
> Lloyd Kvam wrote:
>
>> I did not attempt to figure out your problem, the cgitb module with
>> its traceback facility usually helps a great deal with debugging an
>> errant cgi script.
>
>
> When I used cgitb, it gave errno 9, 'Bad file descriptor' to this line:
>
> sock.connect((configuration.get_search_server_ip(), \
> configuration.get_search_server_port()))
>
> Evaluated, that comes to:
>
> sock.connect(("127.0.0.1", 1374))
>
> Cgitb has helped me know what I need to be using right, but it won't
> explain the socket concept I'm missing--that's why I e-mailed the list.
> Do you or anyone else on the list know what needs to be changed about
> the socket so the above line will be corrected?
>
> TIA
>
>>
>> However, wouldn't it be simpler to use fastCGI or an equivalent
>> connection
>> between the web server and the persistent process?
>
>
> I looked in to it. That's great if I want to have my private server
> running things, but I want to have something that people can install PnP
> without repeating the extras I set up.
>
>>
>>> def get_page_from_oracle(self):
>>> self.check_and_start_oracle()
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sockIn = sock.makefile("r")
>>> sockOut = sock.makefile("wb")
>>> sock.close()
>>> try:
>>> sock.connect((configuration.get_search_server_ip(), \
>>> configuration.get_search_server_port()))
>>> for current_environment_key in os.environ.keys():
>>> sockOut.write("environmental_variable " + \
>>> current_environment_key + "\r\n")
>>> cPickle.dump(os.environ[current_environment_key],
>>> sockOut)
>>> for cgi_key in cgi.FieldStorage().keys():
>>> sockOut.write("cgi_value " + cgi_key + "\r\n")
>>> cPickle.dump(cgi.FieldStorage[cgi_key])
>>> sockOut.write("\r\n")
>>> result = cPickle.load(sockIn)
>>> sockOut.close()
>>> sockIn.close()
>>> except socket.error, e:
>>> return "Content-type: text/html\n\n<h1>There was an error
>>> loading this page.</h1>" + str(e)
>
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-443-6155
fax: 801-459-9582