Sto cercando di fare una richiesta HEAD di una pagina utilizzando Python 2.Fare richiesta HEAD HTTP con urllib2 da Python 2
sto cercando
import misc_urllib2
.....
opender = urllib2.build_opener([misc_urllib2.MyHTTPRedirectHandler(), misc_urllib2.HeadRequest()])
con misc_urllib2.py
contenente
class HeadRequest(urllib2.Request):
def get_method(self):
return "HEAD"
class MyHTTPRedirectHandler(urllib2.HTTPRedirectHandler):
def __init__ (self):
self.redirects = []
def http_error_301(self, req, fp, code, msg, headers):
result = urllib2.HTTPRedirectHandler.http_error_301(
self, req, fp, code, msg, headers)
result.redirect_code = code
return result
http_error_302 = http_error_303 = http_error_307 = http_error_301
Ma io sono sempre
TypeError: __init__() takes at least 2 arguments (1 given)
.210
Se io faccio solo
opender = urllib2.build_opener(misc_urllib2.MyHTTPRedirectHandler())
allora funziona bene
fa che consentono di impostare altri objs richiesta? Vedi il mio OP, MyHTTPRedirectHandler – Wizzard
Abbiamo riscontrato un errore utilizzando questo approccio. Successivamente qualcuno ha voluto verificare un URL HTTPS, per il quale è necessario utilizzare un metodo diverso: 'httplib.HTTConnection()' – ericzundel