You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by as...@free.fr on 2018/12/05 15:49:11 UTC

Use JavaScript client with HTTP python server

Hello everyone :)

I would like to use Thrift API directly from a web service with Javascript (not NodeJS).
So, in order to try that, I generated a Python HTTP server and a Javascript client on a simple HTML page.

But when I try to send a request from my Browser (Google Chrome) to the Python server, I have the following error :

OPTIONS http://localhost:9090/ 501 (Unsupported method ('OPTIONS'))
flush @ thrift.js:390
DealerClient.send_getTimestamp @ Dealer.js:638
DealerClient.getTimestamp @ Dealer.js:615
update_timestamp @ index.html:33
onclick @ index.html:14
thrift.js:390 Access to XMLHttpRequest at 'http://localhost:9090/' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:9090/'.

The entire code with the complete error can be found here: https://pastebin.com/LqPUHH3g
It seems the HTTPServer don't know how to deal with the 'OPTIONS' HTTP method which is sent before the requested command (which is supposed to be sent by POST HTTP method) and doesn't respond with headers to the browser.

So, If one of you have an idea/an example of a working Javascript/Python client/server application, it could be nice :)

Regards,
Thibault