Making HTTP HEAD request with urllib2 from Python 2

后端 未结 4 1417
无人共我
无人共我 2020-11-27 18:51

I\'m trying to do a HEAD request of a page using Python 2.

I am trying

import misc_urllib2
.....
opender = urllib2.build_opener([misc_urllib2.MyHTTPR         


        
4条回答
  •  醉话见心
    2020-11-27 19:12

    The problem lies with your class HeadRequest, which inherits from urllib2.Request. According to doc, urllib2.Request.__init__ signature is

     __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False) 
    

    so you must pass an url argument to it. In your second try, you just do not use HeadRequest, this is why it works.

提交回复
热议问题