Search code examples
python-3.xmechanizemechanize-python

what does mechanize tag br.set_handle_gzip do?


I'm trying python mechanize module in order to write some scripts. When i run it i get the following error.What actually is this set_handle_gzip ?

manoj@ubuntu:~/pyth$ python rock.py                                    │                                                                      
rock.py:15: UserWarning: gzip transfer encoding is experimental!       │                                                                      
  br.set_handle_gzip(True)                                             │                                                                      
Traceback (most recent call last):                                     │                                                                      
  File "rock.py", line 60, in <module>                                 │                                                                      
    br.follow_link(text='Sign out')                                    │                                                                      
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line│                                                                      
 569, in follow_link                                                   │                                                                      
    return self.open(self.click_link(link, **kwds))                    │                                                                      
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line│                                                                      
 553, in click_link                                                    │                                                                      
    link = self.find_link(**kwds)                                      │                                                                      
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line│                                                                      
 620, in find_link                         
    raise LinkNotFoundError()                                          │                                                                      
mechanize._mechanize.LinkNotFoundError 

and how can i overcome this error?


Solution

  • The gzip transfer encoding warning is generated because of the following line:

    br.set_handle_gzip(True)
    

    To remove the warning message, change True to False.

    As for the error message, it is because your script is unable to find a link that reads 'Sign out' on the page that you're working with.

    br.follow_link(text='Sign out') 
    

    Change the value of text in this line to the same value as is used on the page. That will solve your problem.