콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6666 화면

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



아바타
취소
베스트 답변

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, 
아바타
취소