what does mechanize tag br.set_handle_gzip do?

回眸只為那壹抹淺笑 提交于 2019-12-31 03:48:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11009398/what-does-mechanize-tag-br-set-handle-gzip-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!