Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Python XML-RPC Server with clientside Javascript

Question posted by: akineko (Guest) on July 5th, 2008 05:05 AM
Hello everyone,

I have used Python SimpleXMLRPCServer to expose several methods to be
used.
My Python script creates a free-standing server and not a CGI script.
I have tested its exposed methods using the following Python script:

import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:8765')
print s.my_method()

I tested all methods one by one and they are working as I intended.

Now, I want to use those exposed methods from a static html file
(without any web server) using client side javascript. (i.e. Open
File... from the browser (or file://...) )

I found many XML-RPC examples with javascript but all of them I found
assume XML-RPC services to be deliver from a web server, such as
Apache, as a CGI.

I tried those examples with placing 'http://localhost:8765' as url,
but they didn't work.

How can I utilize the XML-RPC services from a free-standing
SimpleXMLRPCServer in a static HTML page?
Is it possible to do such? Do I need web server to use client-side
javascript?

I have searched the Internet for similar questions. I found similar
postings but there were no clear answers.

Any suggestions will be highly appreciated.
Best regards,
Aki Niimura
paul's Avatar
paul
Guest
n/a Posts
July 5th, 2008
10:45 AM
#2

Re: Python XML-RPC Server with clientside Javascript
akineko schrieb:
Quote:
Hello everyone,
>
I have used Python SimpleXMLRPCServer to expose several methods to be
used.
My Python script creates a free-standing server and not a CGI script.
I have tested its exposed methods using the following Python script:
>
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:8765')
print s.my_method()
>
I tested all methods one by one and they are working as I intended.
>
Now, I want to use those exposed methods from a static html file
(without any web server) using client side javascript. (i.e. Open
File... from the browser (or file://...) )
>
I found many XML-RPC examples with javascript but all of them I found
assume XML-RPC services to be deliver from a web server, such as
Apache, as a CGI.

I'd think this has nothing to do with CGI vs. "free-standing", the
client couldn't tell the difference anyway.
It looks like you're running in the "same origin" javascript security
restriction enforced by the browser. That is, the origin of your
javascript is file://... and you're trying to access
http://localhost:8765. This is not allowed.

hth
Paul


akineko's Avatar
akineko
Guest
n/a Posts
July 5th, 2008
12:15 PM
#3

Re: Python XML-RPC Server with clientside Javascript
Hello Paul,

Thank you very much for your prompt and clear answer.
I didn't know the "same origin" javascript security policy (as I'm not
familiar with javascript).
After reading the description of the "same origin" javascript policy,
I think you are absolutely correct.
The security policy does make sense.
However, if that is the case, it seems I have only two options to make
my project work:
(1) Place my XML-CGI services under a web server so that both HTML
page and RPC services are coming from the same origin
(2) Expand Python DocXMLRPCServer, which renders a HTML page, to
implement my own HTML page from it

I wanted to run the program as a standalone one (no external web
server required).
Therefore, (2) seems the only option I have to make it work.

Anyway, thank you for solving my days-long question.

Best regards,
Aki Niimura

On Jul 5, 3:39 am, paul <p...@subsignal.orgwrote:
Quote:
>
I'd think this has nothing to do with CGI vs. "free-standing", the
client couldn't tell the difference anyway.
It looks like you're running in the "same origin" javascript security
restriction enforced by the browser. That is, the origin of your
javascript is file://... and you're trying to accesshttp://localhost:8765. This is not allowed.
>
hth
Paul



 
Not the answer you were looking for? Post your question . . .
189,876 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors