Skip to Content
Menu
This question has been flagged
1 Reply
5903 Views

I have a self written modul with a controller with the


class import_pdf(http.Controller):

    @http.route('/pdfimport/parsefile',type='json', auth='user')
    def parsefile(self, **kw):  

            .....


on the same modul i could execute this command inside a js script with


ajax.jsonRpc("/pdfimport/parsefile", 'call', {'pdf' : b64 })


now i like to execute the same command from an external python script and have found this libary: https://github.com/OCA/odoorpc but i dont find the right way to execute the command like in the javascript file



Avatar
Discard
Best Answer

Hello,

Using Python you can just use the Requests library. Here is my controller:

class OdooHelp3(http.Controller):
    @http.route('/test/', auth='public', type="json")
        def index(self, **kw):
            response = request.jsonrequest
            return response

Here is my Python code which makes the request:

import requests
data = {
    "hello": "world"
}
response = requests.post("http://localhost:8069/test", json=data)
print(response.json())

And here is my response:

{'jsonrpc': '2.0', 'id': None, 'result': {'hello': 'world'}}
I would Requests is the most common library to use in this instance.

EDIT:
I can see your question has user authentication, look at this answer on how you would implement that into requests

If you need any clarification please leave a comment,

Thanks, 
Avatar
Discard