-1

I want to read a url in python but I get error with different ways:

import urllib
link = "http://data.europa.eu/esco/isco/C0110"
f = urllib.urlopen(link)
myfile = f.read()
print(myfile)

HTTPError: HTTP Error 406: Not Acceptable

link = "http://data.europa.eu/esco/isco/C0110"
f = requests.get(link)
print(f)

<Response [406]>

Any idea?

ecm
  • 2,583
  • 4
  • 21
  • 29
  • 1
    Does this answer your question? [What is "406-Not Acceptable Response" in HTTP?](https://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http) – shmee Aug 06 '21 at 09:09
  • No I read that page before honestly –  Aug 06 '21 at 09:10
  • 1
    You've read it… did you understand what it said, and did you try to do anything in response to it? – deceze Aug 06 '21 at 09:12

2 Answers2

0

In this particular case you can overcome HTTP 406 by providing appropriate headers as follows:-

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36',
    'Accept-Encoding': '*',
    'Accept': 'text/html',
    'Accept-Language': '*'}
0

The link is broken/invalid. As per the site, the following link http://data.europa.eu/esco/isco/C0110 is not a URL but a URI.

It seems they have an API setup for the data.

You can either;

  1. Check out the API and configure it
    https://ec.europa.eu/esco/portal/api

OR

  1. Use a module like BeautifulSoup4 for web scraping the page from which you want the content.
Primus
  • 36
  • 5