Error with form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ATNC33
    New Member
    • Sep 2012
    • 7

    Error with form

    Hello

    I'm new here, but I need some help. I'm trying to do a login into the safilo website (http://www.safilonet.safilo.com/) running python code.
    There is an error that I'm not capable to find where it is:

    ---------- run.py
    Code:
    """UPDATE SAFILO"""
            
            ss = SafiloSupplier(updateBrands=True)
            
            #ss.resetLog()
            #ss.printBrands()
            
            brds = ss._brands
            
            start_at_brand = ''
            print 'Brands before filtering:', len(brds)
            if len(start_at_brand) > 0:
                while len(brds) > 0 and brds[0]._ref != start_at_brand:
                    brds.pop(0)
            print 'Brands after filtering:', len(brds)
            #sys.exit(0)
            
            #ss.clearAllModelFromSql()
            
            for b in brds:
                ss.addToLog('** BRAND %s... **' % b._ref, True)
                
                print '*** Updating catalog... ***'
                ss.updateCatalog(b._ref)
                
                print '*** Expanding models... ***'
                ss.expandModels(b._ref)
    
    ----------- Supplier.py
    
    class SafiloSupplier(Supplier):
        '''
        100% faulty HTML webscrapping client for Safilo supplier.
        Uses hand-made MiniTidy class for converting HTML to valid XML for further parsing.
        '''
        
        def __init__(self, updateBrands=False, login=True):
            Supplier.__init__(self)
            
            self._name = 'Safilo'
            self._username = '******' 
            self._password = '******' 
            self._baseUrl = 'http://www.safilonet.safilo.com'
            self._ignoreBrandsWithRef = ['BLU', 'SAF']
            self._root += 'safilo\\'
            self._brandsPC = PersistLite(instance=Brand(), path=self._root + 'brands\\brands.sqlite')
            self.last_logged_in = None
            
            if login: self.login()
            
            if updateBrands:
                self.updateBrands()    # also saves
            else:
                self.loadBrands()
            
            self.filterBrands()
        
        
        def check_login(self):
            n = datetime.datetime.now()
            dt = n - self.last_logged_in
            if dt.seconds > 120:
                print 'Logged in for %d seconds. Logging in again...' % dt.seconds
                self.login()
        
        ##webapp/commerce/safilo/jsp/logon.jsp
        
        def login(self):
            url = self._baseUrl + '/webapp/commerce/logon'
            self._br.open(url, timeout=30.0)
            self._br.select_form('logon')
            self._br.form['login'] = self._username
            self._br.form['password'] = self._password
            self._br.submit()
            
            if self._verbose: print 'Login successful.\n'
            
            self.last_logged_in = datetime.datetime.now()
    
    There is more code in both files, but i think the error is somewhere on this peace of code.
    
    The error presented is:
    
    Traceback (most recent call last):
      File "E:\billy\Projects\GlassInteg\trunk\src\run.py", line 89, in <module>
        go()
      File "E:\billy\Projects\GlassInteg\trunk\src\run.py", line 39, in go
        ss = SafiloSupplier(updateBrands=True)
      File "E:\billy\Projects\GlassInteg\trunk\src\GlassInteg\Supplier.py", line 280, in __init__
        if login: self.login()
      File "E:\billy\Projects\GlassInteg\trunk\src\GlassInteg\Supplier.py", line 302, in login
        self._br.select_form('logon')
      File "build\bdist.win32\egg\mechanize\_mechanize.py", line 524, in select_form
    mechanize._mechanize.FormNotFoundError: no form matching name 'logon'
    Can you please help me?
    Last edited by bvdet; Sep 19 '12, 02:46 PM. Reason: Please use code tags when posting code: [code]....code....[/code]
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It would help to know what that error message is.

    Comment

    • ATNC33
      New Member
      • Sep 2012
      • 7

      #3
      @Rabbit The error message is on the line 82. I haven't still solved this problem! I can't understand what's going on...

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        It sounds like a pretty clear error message. There's no form on that page named logon.

        Comment

        • ATNC33
          New Member
          • Sep 2012
          • 7

          #5
          There is a form named logon,

          Take a look at this source code:

          Code:
          <form action="https://www.safilonet.safilo.com/webapp/commerce/logon" method="post" target="_top" name="logon" onsubmit="return checkFields();" enctype="application/x-www-form-urlencoded">

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Which page are you getting that from? Because that form may exist on http://www.safilonet.safilo.com but that's not where you're trying to login from. In your code, you're trying to login from http://www.safilonet.safilo.com/webapp/commerce/logon and that page has no such form.

            Comment

            Working...