Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
14649 Visualizzazioni

Why do I get ImportError: No module named http ?

When installing my module I get the following error:

  File "/home/michael/workspace/openerp/server/openerp/addons/my_punchcard/controllers/my_controller.py, line 1, in <module>
     import openerp.http as http
ImportError: No module named http 
Here's line 1 of my code:
import openerp.http as http

so I tried this instead:
 import openerp.addons.web.http as http 

but then I get this error which says it can't find the route attribute.
  File "/home/michael/workspace/openerp/server/openerp/addons/my_punchcard/controllers/my_controller.py", line 48, in my_punchcard 
       @http.route('/web/my_page', type="http")
AttributeError: 'module' object has no attribute 'route'


I am running Version 7.0-20131203-002409 on an Ubuntu server. I'm developing in Eclipse, which shows a red circle with a white X through it by the original Line 1. So I'm guessing Eclipse knows there's no http in openerp.
My code is like that from doc.openerp.com/trunk/web/web_controllers

Avatar
Abbandona
Risposta migliore

Try with: from openerp.addons.web import http as http

Also, Check your eclipse project configuration "PATH"

Avatar
Abbandona
Autore

I still get: AttributeError: 'module' object has no attribute 'route'.

Check your URL Patterns (as described in doc.openerp.com/trunk/web/web_controllers). Is your "my_page" under web ?

Be careful, the doc is for the trunk (8.0dev) not for 7.0.

Autore

Thanks Med Said BARA, I'm wondering if the documentation for trunk is not applicable to V7. That would explain why route doesn't work for me. I found an example from web_diagram that I tried to modify:

<pre><code> from openerp.addons.web.http import Controller, httprequest

class MyClass(Controller): _cp_path = "/web/mypage"

@httprequest
def index(self):
    return "<html><head></head><body>TESTING 123</body></html>"

</code></pre>

Autore

Not exactly as I wanted that to be posted. However no matter what URL i try (or _cp_path I set) I can't get it to find the document. I would have thought the return would do it. However maybe I need a view?

However at least with this code I am getting no errors when I restart the server.

openerp.http.httprequest(f) Deprecated since version 8.0.

Just to confirm, and as stated here: https://doc.openerp.com/trunk/server/routing/ . route() is for V8

Autore

That is certainly my problem. I was using code in version 7.0 meant for version 8. I now use a simpler _cp_path='/my_module' and the function name becomes the final part of the URL. I saw in the web_diagram controller which used @httprequest, that it had a function named index. And Point-of-sale has a _cp_path of '/pos', which made me think that perhaps my path was too long. Now i also understand why @httprequest doesn't specify the complete URL the way route does, @httprequest accesses any function with @httprequest declared above it using the function name rather than the @route argument.

Post correlati Risposte Visualizzazioni Attività
1
lug 25
3145
1
mar 18
14308
4
ott 20
6740
2
mar 16
5053
3
gen 18
13614