Ejemplo n.º 1
0
 def _scrape(self, query):
     """ Make an HTTP GET request to the tracker
         Note: This runs in its own thread.
     """
     self.spath = "/scrape"
     if not self.https:
         log.warning("Warning: Will not connect to non HTTPS server")
         return
     try:
         if self.proxy_url:
             h = ProxyHTTPSConnection(self.proxy_url, \
                                      username=self.proxy_username, \
                                      password=self.proxy_password, \
                                      ssl_context=self.ssl_ctx)
             s = "https://%s:%d%s%s" % (self.url, self.remote_port, self.spath, query)
             h.putrequest('GET', s)
         else:
             #No proxy url, use normal connection
             h = HTTPSConnection(self.url, self.remote_port, ssl_context=self.ssl_ctx)
             h.putrequest('GET', self.spath+query)
         h.endheaders()
         resp = h.getresponse()
         data = resp.read()
         resp.close()
         h.close()
         h = None
     # urllib2 can raise various crap that doesn't have a common base
     # exception class especially when proxies are used, at least
     # ValueError and stuff from httplib
     except Exception, g:
         def f(r='Problem connecting to ' + self.url + ':  ' + str(g)):
             self._postrequest(errormsg=r)
Ejemplo n.º 2
0
 def _rerequest(self, query):
     """ Make an HTTP GET request to the tracker
         Note: This runs in its own thread.
     """
     log.info("Making announce to " + self.url + ":" + str(self.remote_port))
     if not self.https:
         log.warning("Warning: Will not connect to non HTTPS server")
         return
     try:
         if self.proxy_url:
             h = ProxyHTTPSConnection(self.proxy_url, \
                                      username=self.proxy_username, \
                                      password=self.proxy_password, \
                                      ssl_context=self.ssl_ctx)
             s = "https://%s:%d%s%s" % (self.url, self.remote_port, self.path, query)
             h.putrequest('GET', s)
             
             # I suggest that for now, until there is a better solution in python, 
             # that connections with socks proxies be done with:
             #  socat TCP4-LISTEN:5555,fork SOCKS4A:s,socksport=9050 
             #  or use Privoxy:
             #  127.0.0.1:8118
                                 
         else:
             #No proxy url, use normal connection
             h = HTTPSConnection(self.url, self.remote_port, ssl_context=self.ssl_ctx)
             h.putrequest('GET', self.path+query)
         h.endheaders()
         resp = h.getresponse()
         data = resp.read()
         resp.close()
         h.close()
         h = None
     # urllib2 can raise various crap that doesn't have a common base
     # exception class especially when proxies are used, at least
     # ValueError and stuff from httplib
     except Exception, g:
         def f(r='Problem connecting to ' + self.url + ':  ' + str(g)):
             self._postrequest(errormsg=r)