Search code examples
pythonhttpsodoowerkzeug

In Odoo,what's the difference between the http and https when it comes to writing the controllers?There is an error


I have wirtten a controllers in an Odoo module.There is no problem using postman to test the interface in the debug environment based on http.However,there is some problem using postman to test the interface in the production environment based on https.

Python version 2.7.12

Odoo version 10.0

werkzeug version 0.11.11

Here is my code.Please help me,thank you.

Production environment and the protocol is https.

controllers.py

# -*- coding:utf-8 -*-
from odoo.http import Controller
from odoo.http import route
from odoo.http import request

class PhotoPruner(Controller):
    @route('/<string:type>/photo/size/<int:record_id>', type='http', auth='none', methods=['GET'], csrf=False)
    def get_info(self, **kwargs):
        type = kwargs.get('type')
        record_id = kwargs.get('record_id')
        return 'ok'

postman test The result of postman test

log error info The picture of log error

Debug environment and the protocol is http

There is no problem.

I receive the 'ok' when I get the http://127.0.0.1/task/photo/size/146


Solution

  • Odoo routing supports two type of requests, http and json. you are getting error on production probably because of using https which is a type not even supported. When you are using web servers nginx or apache in front of your Odoo application and reverse proxy to Odoo application, you are probably using http protocol between webserver and application communication. Check the proxy_pass of your nginx configuration, probably the reverse proxy is http://127.0.0.1:8069 (if you are nginx, or respective apache virtual host configuration line).

    For more information about Odoo web controllers, please refer to the official documentation of Odoo, it is specifically mentioned that request type can be http or json.