2013-07-26 65 views
2

我想OpenERP的用戶客戶端的IP地址,而我的模塊中從Web模塊添加一些代碼副本,如下:如何獲得OpenERP的客戶端IP

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 

但得到錯誤:AttributeError的:「名單」對象有沒有屬性「的HttpRequest」 請幫助我,非常感謝

+0

你檢查了'req'的類型?它似乎是一個列表。更新你調用函數 –

回答

1

導入此請求對象

from openerp.http import request 

,並使用下面的代碼來獲取用戶IP:

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

它爲我

+0

的方式,它工作的很完美,但是它在eclipse中標記爲「來自import:environ的未定義變量」。你知道如何避免這種情況嗎? – MouTio