<div dir="ltr">I am getting an Internal Server Error 500 when i run my client code. I am trying to call a function at the server side which for now only returns a string. Meanwhile this calling i also set the header of HTTP request. Following are my client and server code. Am i doing something wrong? <br>
<br><span style="color: rgb(0, 0, 153);">#-----------------------Server code-----------------------------</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">import SimpleXMLRPCServer</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">class AuthenticationFunctions:</span><span style="color: rgb(0, 0, 153);"></span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> def system_auth(self):</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"> # No need to print here if you are going to print it at the client side. Return it instead.</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> return "something..."</span><span style="color: rgb(0, 0, 153);"></span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">server.register_instance(AuthenticationFunctions())</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">server.serve_forever()</span><br><br><br>#-----------------------Client code-----------------------------<br>import sha,random, os, time, sha, quopri, xmlrpclib<br><br>class SecureTransport(xmlrpclib.Transport):<br>
def set_authorization(self, ustring, text_ucert):<br> self.authorization = quopri.encodestring("%s:%s" % (ustring,text_ucert))<br> def send_request(self, connection, handler, request_body):<br>
connection.putrequest("POST", handler)<br> connection.putheader("Authorization","Basic %s" % self.authorization)<br><br>def caller():<br> #Opening file named newcert.pem in which certificate generated via openssl command is placed<br>
infile = open('newcert.pem', "r+")<br> if infile:<br> text_ucert = infile.read()<br> infile.close()<br><br> #Generating a random string<br> random.seed();<br> ustring_raw="%s_%f_%f"%(os.getpid(),time.time(),random.random())<br>
<br> #For calculating the hash of some arbitrary message<br> hashValue = sha.new()<br> hashValue.update("(.2).ch^kjdw*()!hjsu7@hsue@!jssljdu2837.kd'lsid4vhwoi3821@#1azzZ3234202J83&")<br><br> #Updating the hash with the previously generated random string<br>
hashValue.update(ustring_raw)<br> ustring = quopri.encodestring(hashValue.digest())<br> <br> #Instantiating the transport<br> t = SecureTransport()<br> t.set_authorization(ustring, text_ucert)<br>
server = xmlrpclib.Server('<a href="http://localhost:8000">http://localhost:8000</a>',transport=t)<br> <br> #Calling some arbitrary function at server side<br> print server.system_auth()<br> <br>
caller()<br><br><br><br></div>