Skip to content

Instantly share code, notes, and snippets.

@netdesign
Created October 7, 2011 10:53
Show Gist options
  • Select an option

  • Save netdesign/1270035 to your computer and use it in GitHub Desktop.

Select an option

Save netdesign/1270035 to your computer and use it in GitHub Desktop.
What's the problem?
class httpProxy():
def __init__(self, iolp):
self.countReqs = 0
self.myserv = httpserver.HTTPServer(self.handle_request)
self.myserv.listen(8080)
self.ioloop = iolp
self.thisioloop = iolp.start()
self.client = httpAsyncClient(self.ioloop)
self.clientTwo = httpAsyncClient(self.ioloop)
def handle_request(self, req):
self.client.fetcher(req)
class httpAsyncClient():
def __init__(self, ioloop):
self.httpclient = AsyncHTTPClient()
self.ioloop = ioloop
self.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"
def fetcher(self, req):
self.req = req
self.httpclient.fetch(req.uri, callback=self.handler, headers={"Accept-Encoding":"gzip,deflate", "Referer":"http://www.google.com", "User-Agent":self.userAgent})
def handler(self, response):
resp = ("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % (len(response.body), response.body))
self.req.write(resp)
print "Fetched", self.req.uri, self.req.request_time()
self.req.finish()
iolp = ioloop.IOLoop.instance()
server = httpProxy(iolp)
ERROR:root:Uncaught exception, closing connection.
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/iostream.py", line 301, in wrapper
callback(*args)
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/httpserver.py", line 248, in _on_headers
self.request_callback(self._request)
File "nauauProxy.faster.async.py", line 22, in handle_request
self.client.fetcher(req)
AttributeError: httpProxy instance has no attribute 'client'
ERROR:root:Exception in callback <tornado.stack_context._StackContextWrapper object at 0x1a6fd60>
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/ioloop.py", line 396, in _run_callback
callback()
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/iostream.py", line 301, in wrapper
callback(*args)
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/httpserver.py", line 248, in _on_headers
self.request_callback(self._request)
File "nauauProxy.faster.async.py", line 22, in handle_request
self.client.fetcher(req)
AttributeError: httpProxy instance has no attribute 'client'
class httpProxy():
def __init__(self, iolp):
self.countReqs = 0
self.myserv = httpserver.HTTPServer(self.handle_request)
self.myserv.listen(8080)
self.ioloop = iolp
self.thisioloop = iolp.start()
#self.client =
def handle_request(self, req):
client = httpAsyncClient(req, self.ioloop)
print "One Request"
class httpAsyncClient():
def __init__(self, req, ioloop):
self.httpclient = AsyncHTTPClient()
self.req = req
self.ioloop = ioloop
self.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"
self.httpclient.fetch(req.uri, callback=self.handler, headers={"Accept-Encoding":"gzip,deflate", "Referer":"http://www.google.com", "User-Agent":self.userAgent})
#self.ioloop.start()
print "Fetching", req.uri
def handler(self, response):
resp = ("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % (len(response.body), response.body))
self.req.write(resp)
print "Fetched", self.req.uri, self.req.request_time()
self.req.finish() # THIS IS THE INDICTED LINE
iolp = ioloop.IOLoop.instance()
server = httpProxy(iolp)
class httpProxy():
def __init__(self, iolp):
self.countReqs = 0
self.myserv = httpserver.HTTPServer(self.handle_request)
self.myserv.listen(8080)
self.ioloop = iolp
self.thisioloop = iolp.start()
#self.client =
def handle_request(self, req):
client = httpAsyncClient(req, self.ioloop)
print "One Request"
class httpAsyncClient():
def __init__(self, req, ioloop):
self.httpclient = AsyncHTTPClient()
self.req = req
self.ioloop = ioloop
self.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"
self.httpclient.fetch(req.uri, callback=self.handler, headers={"Accept-Encoding":"gzip,deflate", "Referer":"http://www.google.com", "User-Agent":self.userAgent})
#self.ioloop.start()
print "Fetching", req.uri
def handler(self, response):
resp = ("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % (len(response.body), response.body))
self.req.write(resp)
print "Fetched", self.req.uri, self.req.request_time()
self.req.finish() # THIS IS THE INDICTED LINE
iolp = ioloop.IOLoop.instance()
server = httpProxy(iolp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment