跳至內容
選單
此問題已被標幟
1 回覆
4698 瀏覽次數

What am i doing wrongly with api code?

Every thing works well with Postman api test but I keep having session expired each time i called get controller function on Android App.

I always get a valid session id when authenticating user on ..... https://127.0.0.1/web/session/authenticate

I need guide please.

### My Code Below:###

from odoo import http

from odoo.http import request


class FieldWorker(http.Controller):
# Update Controller

@http.route('/update_worker', type='json', auth='user')

def update_worker(self, **rec):

    if request.jsonrequest:

        if rec['id']:

            fieldworker = request.env['field.workers'].search([('id', '=', rec['id'])])

            if fieldworker:

                fieldworker.write(rec)

            args = {'success': True, 'message': 'Fieldworker Updated'}

    return args


# Get Controller

@http.route('/get_fieldworkers', type='json', auth='user')

def get_fieldworkers(self):

    fieldworker_rec = request.env['field.workers'].search([])

    fieldworkers = []

        for rec in fieldworker_rec:

            vals = {

                'id': rec.id,

                'name': rec.name,

                'community': rec.community,

                'latitudes': rec.latitudes,

                'longitudes': rec.longitudes,

                'team_ids': rec.team_ids,

            }

            fieldworkers.append(vals)

        data = {'status': 200, 'response': fieldworkers, 'message': 'All Fieldworkers Fetched'}               return data

頭像
捨棄

Do you've got a proxy, like nginx?

Do you've got more than one database? and do you filter the database somehow?

作者

@ Blanco,

1. Yes, I use nginx

2. Yes, I did filter the databases like dbfilter = ^%d$

最佳答案

You need to pass that session id in the header of each request after authentication. I suggest you to open your log and when you attemp to get or post something your log will tell you what is missing

頭像
捨棄
作者

@ Abdullah,

I did passed the session id to each request header on the Android App but always get session expired

相關帖文 回覆 瀏覽次數 活動
5
5月 25
9046
0
7月 22
5330
0
7月 21
6914
3
8月 19
5869
3
2月 24
13877