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.

0

Need to raise the Exception based on my Traceback

By
Dasadiya Chaitanya
on 1/7/16, 6:41 AM 516 views

I am working on for generate the request and response on httplib class. In this case I am working on request and response string xml file so that I will send some request to my API server and server reply back to me. the request and response in based on sting xml format.

When I am sending my data with wrong URL format then its gives me an error I need to raise exception based on that below Traceback :

2016-01-07 11:27:40,443 12180 ERROR dynaweld_15_09_15 openerp.netsvc: mismatched tag: line 1, column 959
Traceback (most recent call last):
  File "/home/best/workspace/dynaweld/server/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/best/workspace/dynaweld/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/home/best/workspace/dynaweld/server/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/best/workspace/dynaweld/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/best/workspace/dynaweld/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/best/workspace/dynaweld/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/best/workspace/dynaweld/prod_4/r3x_securepay/model/securepay_login.py", line 147, in test_secure_pay
    doc = minidom.parseString(data)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1930, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
    return builder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
ExpatError: mismatched tag: line 1, column 959



I had tried the below way for raise my exception but its not working well.

from xml.parsers.expat import ExpatError
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _
from openerp import netsvc
import httplib, ConfigParser, urlparse
import xmlrpclib
from xml.dom import minidom
from xml.parsers.expat import ExpatError
from datetime import datetime
import pytz

login_request="""<?xml version='1.0' encoding='UTF-8'?>
                    <SecurePayMessage>
                            <MessageInfo>
                                <messageID>%s_000000000000000</messageID>
                                <messageTimestamp>%s</messageTimestamp>
                                <timeoutValue>%d</timeoutValue>
                                <apiVersion>xml-4.2</apiVersion>
                            </MessageInfo>
                            <MerchantInfo>
                                <merchantID>%s</merchantID>
                                <password>%s</password>
                            </MerchantInfo>
                            <RequestType>Echo</RequestType>
                    </SecurePayMessage>"""%(timestamp_string[:14],timestamp_string,login_data.get('time_out',60),login_data.get('merchant_id',''),login_data.get('password',''))
try:
    urldat = urlparse.urlparse(login_data.get('url'))
    conn = httplib.HTTPSConnection(urldat[1])
    length  = len(login_request)
    GenerateHeaders = {"Content-Type":"text/xml","Content-Length":str(length)}
    conn.request("POST", urldat[2],login_request, GenerateHeaders)
    response = conn.getresponse()
    data = response.read()
except ExpatError:
    raise osv.except_osv(_('Error!'), _('Invalid Server URL from the API Configuration for SecurePay .!'))
except httplib.socket.error:    
    raise osv.except_osv(_('Error!'), _('Internet connection is not available !\t\n please try to test again using enabled Internet connection.'))
finally:
    conn.close()
return data
                                                                                                       

Any help really appreciated :)

         

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 1/8/16, 1:18 AM

Chaitanya,

While rendering an xml view, you cannot raise an exception as we are doing in normal odoo flow.

For that what you can do is to return some unique flag from your controller function to the xml template, which is going to be rendered and then handle it in xml as you want to(normal way is to show that error in your customized way on form/ or raise alert using jquery)

For ex: in your above code, under 'except' inspite of raising an exception, try returning some unique flag to denote error and then in the xml template<t> which is going to be rendered check for that unique flag and show your customized error.

Hope it helps!  

@pavan you are not understand my question properly .please try to check again and then after u can post it.

Dasadiya Chaitanya
on 1/8/16, 3:51 AM

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: 1/7/16, 6:41 AM
Seen: 516 times
Last updated: 1/8/16, 1:18 AM