2
votes

I want to get openerp user client ip address, and in my module add some code copy from web module, as below:

import openerp.addons.web.http as openerpweb
@openerpweb.jsonrequest
def get_ip_address(self, req):
    wsgienv = req.httprequest.environ
    env = dict(
     HTTP_HOST=wsgienv['HTTP_HOST'],
     REMOTE_ADDR=wsgienv['REMOTE_ADDR'],
     )
    _logger.log("env:%d", env)
    return True

But get Error:AttributeError: 'list' object has no attribute 'httprequest' Pls help me ,thanks very much

1
did you check the type of the req? it seems to be a list. Update the way you call the functionPhuc Tran

1 Answers

1
votes

Import the request object here

from openerp.http import request

And use the following code to get the user IP:

wsgienv = request.httprequest.environ
print "User IP: ", wsgienv['REMOTE_ADDR']

It works for me