title: ./xx.py: line 1: import: command not found
body: <p>I am trying to use this <a href="https://stackoverflow.com/questions/2407126/python-urllib2-basic-auth-problem">Python urllib2 Basic Auth Problem</a> bit of code to download a webpage content from an URL which requires authentication. The code I am trying is:</p>
  
  <pre><code> import urllib2, base64
  
  request = urllib2.Request("http://api.foursquare.com/v1/user")
  base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
  request.add_header("Authorization", "Basic %s" % base64string)   
  result = urllib2.urlopen(request)
  </code></pre>
  
  <p>It's showing me:</p>
  
  <pre><code>./xx.py: line 1: import: command not found
  ./xx.py: line 3: syntax error near unexpected token `('
  ./xx.py: line 3: `request = urllib2.Request("http://api.foursquare.com/v1/user")'
  </code></pre>
  
  <p>I am wondering what I am doing wrong? I am using <code>Python 2.7.5</code>. How can I download file contents from an URL which requires authentication?</p>