Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

how to get web httprequest

By
jerry79
on 7/25/13, 11:04 PM 3,940 views

I want to get Httprequest then get the client ip, but use below code in my module have a error. pls help, thanks very much

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

Get Error:AttributeError: 'list' object has no attribute 'httprequest'

0
bala
On 6/18/14, 1:39 AM

sorry for asking question here.  i am not able create object of http request in my own module.

xml:

    <record id="lead_sample" model="ir.ui.view">
        <field name="name">Clients</field>
        <field name="model">document.download</field>
        <field name="arch" type="xml">
            <form string="lead">
                <field name="name"/>
                <button type="action" name="download" string="Downloads" class="oe_button oe_highlight"/>
            </form>
        </field>
    </record>

python:

@openerpweb.httprequest
 def download(self, cr, uid, req, token):       
        return req.make_response(open('/home/cryosave_qrcodes/091_14_00336.png').read,
           [('Content-Type', 'application/octet-stream; charset=binary'),
           ('Content-Disposition', content_disposition('filename.png', req))],
           {'fileToken': token}
        )

I have created this code but i don't know how to create http reqest object in my module

0
Michael Watchorn
On 2/24/14, 3:25 PM

It looks like you call jsonrequest once and httprequest another time. I was able to install this code:
Note: I modified the 2nd line.

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

I didn't import logger.
What URL are you calling to access your function?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/25/13, 11:04 PM
Seen: 3940 times
Last updated: 3/16/15, 8:10 AM