title: What causes "urlopen error [Errno 13] Permission denied" errors?
body: <p>I am trying to write a python (version 2.7.5) CGI script on a Centos7 server.
  My script attempt to download data from librivox's webpage like ... <code>https://librivox.org/selections-from-battle-pieces-and-aspects-of-the-war-by-herman-melville/</code> and my script bombs out with this error:</p>
  
  <pre><code>&lt;class 'urllib2.URLError'&gt;: &lt;urlopen error [Errno 13] Permission denied&gt; 
        args = (error(13, 'Permission denied'),) 
        errno = None 
        filename = None 
        message = '' 
        reason = error(13, 'Permission denied') 
        strerror = None
  </code></pre>
  
  <p>I have shutdown <code>iptables</code> I can do things like `wget -O- <a href="https://librivox.org/selections-from-battle-pieces-and-aspects-of-the-war-by-herman-melville/" rel="nofollow">https://librivox.org/selections-from-battle-pieces-and-aspects-of-the-war-by-herman-melville/</a>' without error.  Here is the bit of code were the error occurs:</p>
  
  <pre><code>def output_html ( url, appname, doobb ):
          print "url is %s&lt;br&gt;" % url
          soup = BeautifulSoup(urllib2.urlopen( url ).read())
  </code></pre>
  
  <p>Update: Thanks Paul and alecxe I have updated my code to be like so:</p>
  
  <pre><code>def output_html ( url, appname, doobb ):
          #hdr = {'User-Agent':'Mozilla/5.0'}
          #print "url is %s&lt;br&gt;" % url
          #req = url2lib2.Request(url, headers=hdr)
          # soup = BeautifulSoup(urllib2.urlopen( url ).read())
          headers = {'User-Agent':'Mozilla/5.0'}
          # headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36'}
          response = requests.get( url, headers=headers)
  
          soup = BeautifulSoup(response.content)
  </code></pre>
  
  <p>... and I get a slightly different error when ...</p>
  
  <pre><code>response = requests.get( url, headers=headers)
  </code></pre>
  
  <p>... gets called ...</p>
  
  <pre><code>&lt;class 'requests.exceptions.ConnectionError'&gt;: ('Connection aborted.', error(13, 'Permission denied')) 
        args = (ProtocolError('Connection aborted.', error(13, 'Permission denied')),) 
        errno = None 
        filename = None 
        message = ProtocolError('Connection aborted.', error(13, 'Permission denied')) 
        request = &lt;PreparedRequest [GET]&gt; 
        response = None 
        strerror = None
  </code></pre>
  
  <p>... the funny thing is wrote a command line version of this script and it works fine and looks something like this ...</p>
  
  <pre><code>def output_html ( url ):
          soup = BeautifulSoup(urllib2.urlopen( url ).read())
  </code></pre>
  
  <p>Very strange don't you think?</p>
  
  <p>Update:
  This question may already have an answer here:
  urllib2.HTTPError: HTTP Error 403: Forbidden 2 answers </p>
  
  <p><strong>NO THEY DO NOT ANSWER THE QUESTION</strong></p>