<div dir="ltr">I am getting an Internal Server Error&nbsp; 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);">&nbsp;&nbsp;&nbsp; def system_auth(self):</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # 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);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;something...&quot;</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((&quot;localhost&quot;, 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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def set_authorization(self, ustring, text_ucert):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.authorization = quopri.encodestring(&quot;%s:%s&quot; % (ustring,text_ucert))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def send_request(self, connection, handler, request_body):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connection.putrequest(&quot;POST&quot;, handler)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connection.putheader(&quot;Authorization&quot;,&quot;Basic %s&quot; % self.authorization)<br><br>def caller():<br>&nbsp;&nbsp;&nbsp; #Opening file named newcert.pem in which certificate generated via openssl command is placed<br>
&nbsp;&nbsp;&nbsp; infile = open(&#39;newcert.pem&#39;, &quot;r+&quot;)<br>&nbsp;&nbsp;&nbsp; if infile:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; text_ucert = infile.read()<br>&nbsp;&nbsp;&nbsp; infile.close()<br><br>&nbsp;&nbsp;&nbsp; #Generating a random string<br>&nbsp;&nbsp;&nbsp; random.seed();<br>&nbsp;&nbsp;&nbsp; ustring_raw=&quot;%s_%f_%f&quot;%(os.getpid(),time.time(),random.random())<br>
<br>&nbsp;&nbsp;&nbsp; #For calculating the hash of some arbitrary message<br>&nbsp;&nbsp;&nbsp; hashValue = sha.new()<br>&nbsp;&nbsp;&nbsp; hashValue.update(&quot;(.2).ch^kjdw*()!hjsu7@hsue@!jssljdu2837.kd&#39;lsid4vhwoi3821@#1azzZ3234202J83&amp;&quot;)<br><br>&nbsp;&nbsp;&nbsp; #Updating the hash with the previously generated random string<br>
&nbsp;&nbsp;&nbsp; hashValue.update(ustring_raw)<br>&nbsp;&nbsp;&nbsp; ustring&nbsp; =&nbsp; quopri.encodestring(hashValue.digest())<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; #Instantiating the transport<br>&nbsp;&nbsp;&nbsp; t = SecureTransport()<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; t.set_authorization(ustring, text_ucert)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; server = xmlrpclib.Server(&#39;<a href="http://localhost:8000">http://localhost:8000</a>&#39;,transport=t)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; #Calling some arbitrary function at server side<br>&nbsp;&nbsp;&nbsp; print server.system_auth()<br>&nbsp;&nbsp;&nbsp; <br>
caller()<br><br><br><br></div>