title: use proxy in python to fetch a webpage
body: <p>I am trying to write a function in Python to use a public anonymous proxy and fetch a webpage, but I got a rather strange error.
  <br>The code (I have Python 2.4):</p>
  
  <pre><code>import urllib2    
  def get_source_html_proxy(url, pip, timeout):
  # timeout in seconds (maximum number of seconds willing for the code to wait in
  # case there is a proxy that is not working, then it gives up) 
      proxy_handler = urllib2.ProxyHandler({'http': pip})
      opener = urllib2.build_opener(proxy_handler)
      opener.addheaders = [('User-agent', 'Mozilla/5.0')]
      urllib2.install_opener(opener)
      req=urllib2.Request(url)
      sock=urllib2.urlopen(req)
      timp=0 # a counter that is going to measure the time until the result (webpage) is
             # returned
      while 1:
          data = sock.read(1024)
          timp=timp+1
          if len(data) &lt; 1024: break
          timpLimita=50000000 * timeout
          if timp==timpLimita: # 5 millions is about 1 second
              break
      if timp==timpLimita:
          print IPul + ": Connection is working, but the webpage is fetched in more than 50 seconds. This proxy returns the following IP: " + str(data)
          return str(data)
      else:
          print "This proxy " + IPul + "= good proxy. " + "It returns the following IP: " + str(data)
          return str(data)
  # Now, I call the function to test it for one single proxy (IP:port) that does not support user and password (a public high anonymity proxy)
  #(I put a proxy that I know is working - slow, but is working)
  rez=get_source_html_proxy("http://www.whatismyip.com/automation/n09230945.asp", "93.84.221.248:3128", 50)
  print rez
  </code></pre>
  
  <p>The error:</p>
  
  <p>Traceback (most recent call last):</p>
  
  <p>File "./public_html/cgi-bin/teste5.py", line 43, in ?</p>
  
  <p>rez=get_source_html_proxy("<a href="http://www.whatismyip.com/automation/n09230945.asp" rel="nofollow noreferrer">http://www.whatismyip.com/automation/n09230945.asp</a>", "xx.yy.zzz.ww:3128", 50)</p>
  
  <blockquote>
    <p>File "./public_html/cgi-bin/teste5.py", line 18, in get_source_html_proxy
       sock=urllib2.urlopen(req)<br>
     File "/usr/lib64/python2.4/urllib2.py", line 130, in urlopen
       return _opener.open(url, data)<br>
     File "/usr/lib64/python2.4/urllib2.py", line 358, in open
       response = self._open(req, data)<br>
     File "/usr/lib64/python2.4/urllib2.py", line 376, in _open
       '_open', req)<br>
     File "/usr/lib64/python2.4/urllib2.py", line 337, in _call_chain
       result = func(*args)<br>
     File "/usr/lib64/python2.4/urllib2.py", line 573, in 
       lambda r, proxy=url, type=type, meth=self.proxy_open: \<br>
     File "/usr/lib64/python2.4/urllib2.py", line 580, in proxy_open
       if '@' in host:<br>
    TypeError: iterable argument required<br></p>
  </blockquote>
  
  <p>I do not know why the character "@" is an issue (I have no such in my code. Should I have?)
  <br>Thanks in advance for your valuable help.</p>