3

I have a Python script that can log into Odoo using RPC calls to the jsonrpc url. The scripts works if I run it on the Odoo server and point it directly to Odoo.

login_parms = {
"id": conversation_id,
"jsonrpc": "2.0",
"method": "call",
"params": {
    "args": [database, username, password],
    "method": "login", "service": "common"}}


response = requests.get(
    url,
    json=login_parms,
    headers={'Content-Type': 'application/json', }) 

However, when I try and run the script remotely, I receive a 400:

Function declared as capable of handling request of type 'json' but called with a request of type 'http'

I'm using nginx as a proxy and my best guess is it is not correctly sending 'json' as the mime type. I've tried adding the following location block to my server block:

location /jsonrpc {
    proxy_pass http://127.0.0.1:8069/jsonrpc;
    proxy_redirect off;
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 300M;
    default_type application/json;
}

But I am receiving the same 400 error.

Pengo
  • 470
  • 1
  • 5
  • 17

1 Answers1

3

I was sending my RPC calls to http, which was redirecting to https. The redirect was not passing along the the json mime type. When I started sending my RPC calls directly to https, Odoo received the json and responded as expected.

For the record, here is the location block code:

    location /jsonrpc {
    proxy_pass http://127.0.0.1:8069;
    proxy_redirect off;
    proxy_set_header HOST $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Content-Type application/json;
    client_max_body_size 300M;
}   
Pengo
  • 470
  • 1
  • 5
  • 17