urllib.error.HTTPError: HTTP Error 403: Forbidden Python
<p>My code:    </p>

<pre><code>import sqlite3, os, urllib.request
from xml.dom import minidom

if os.path.exists("data.db"):
  con = sqlite3.connect("data.db")
  cursor = con.cursor()
  sql = "SELECT * FROM data WHERE test= '123'"
  cursor.execute(sql)
else:
  print("ERROR")

for dsatz in cursor:
  #print(dsatz)
  link = 'http://test.org/publication/' + dsatz[0] + '' + dsatz[1] +'/bib'
  #print(link)

  web_data = urllib.request.urlopen(link)
  xmldoc = minidom.parse(web_data)

  di = xmldoc.getElementsByTagName("document-id")[:1]

  for x in di:
      publicationcountry = x.getElementsByTagName("country")[0].firstChild.data
      publicationdocnumber = x.getElementsByTagName("doc-number")[0].firstChild.data
      punlicationkind = x.getElementsByTagName("kind")[0].firstChild.data
      publicationdate = x.getElementsByTagName("date")[0].firstChild.data     

      sql = "INSERT INTO link_xml_data VALUES('" \
      + publicationcountry + "', '" \
      + str(publicationdocnumber) + "', '" \
      + punlicationkind + "')"

      con.close()
</code></pre>

<p>But after like 15 links I get the ERROR :</p>

<pre><code>Traceback (most recent call last):
  File "C:\Users\j\3.py", line 34, in &lt;module&gt;
    web_data = urllib.request.urlopen(link)
  File "C:\Users\j\Python35-32\lib\urllib\request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\j\Python35-32\lib\urllib\request.py", line 472, in open
    response = meth(req, response)
  File "C:\Users\j\Python35-32\lib\urllib\request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\j\Python35-32\lib\urllib\request.py", line 510, in error
    return self._call_chain(*args)
  File "C:\Users\j\Python35-32\lib\urllib\request.py", line 444, in _call_chain
    result = func(*args)
  File "C:\Users\j\Python35-32\lib\urllib\request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
</code></pre>

<p>What do should I add or change?</p>

<p>The web server is telling you that link is forbidden.  There's (probably) nothing wrong with your code.</p>

<p>Do some links always work and other links always fail, or does the pattern change over time?</p>

<p>After getting a 403 Forbidden response, have you tried going back and re-requesting one of the earlier successful links?</p>

<p>Perhaps the server eventually recognizes you as a web scraper and is telling you to go away?</p>

python xml parsing