Exemplo n.º 1
0
 def http_Resp(self):
     rslt = {}
     for sito in self.lst_urls:
         try:
             s = httplib2.Http()
             code, resp = s.request(sito, body=None)
             if code.previous:
                 xbmc.log(
                     "r1 http_Resp: %s %s %s %s" %
                     (code.status, code.reason, code.previous['status'],
                      code.previous['-x-permanent-redirect-url']),
                     level=xbmc.LOGNOTICE)
                 rslt['code'] = code.previous['status']
                 rslt['redirect'] = code.previous[
                     '-x-permanent-redirect-url']
                 rslt['status'] = code.status
             else:
                 rslt['code'] = code.status
         except httplib2.ServerNotFoundError as msg:
             # sia per mancanza di ADSL che per i siti non esistenti
             rslt['code'] = -2
         except socket.error as msg:
             # per siti irraggiungibili senza DNS corretti
             #[Errno 111] Connection refused
             rslt['code'] = 111
         except:
             rslt['code'] = 'Connection error'
     return rslt
Exemplo n.º 2
0
def http_Resp(lst_urls):
    rslt = {}
    for sito in lst_urls:
        try:
            s = httplib2.Http()
            code, resp = s.request(sito, body=None)
            if code.previous:
                print("r1 http_Resp: %s %s %s %s" %
                      (code.status, code.reason, code.previous['status'],
                       code.previous['-x-permanent-redirect-url']))
                rslt['code'] = code.previous['status']
                rslt['redirect'] = code.previous['-x-permanent-redirect-url']
                rslt['status'] = code.status
            else:
                rslt['code'] = code.status
        except httplib2.ServerNotFoundError as msg:
            # both for lack of ADSL and for non-existent sites
            rslt['code'] = -2
        except socket.error as msg:
            # for unreachable sites without correct DNS
            # [Errno 111] Connection refused
            rslt['code'] = 111
        except:
            rslt['code'] = 'Connection error'
    return rslt