what does mechanize tag br.set_handle_gzip do?
Asked Answered
N

1

1

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?

Nigrescent answered 13/6, 2012 at 6:34 Comment(1)
Did you really run mechanize under Python 3.x? If so, how? There's my original question: #13210278Archeology
A
2

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.

Admissive answered 3/11, 2012 at 21:29 Comment(2)
but what does set_handle_gzip actually do? Could there be any negative repercussions from changing True to False?Benenson
it lets the server know that it can receive gzip'ed content, i.e. a compressed version of the content that saves bandwidth but may take additional CPU power to decompress.Delvalle

© 2022 - 2024 — McMap. All rights reserved.