Python parse XML from online web service
Question: I have been trying to use python to parse an XML that I get from a webserver.
The link to the XML is <http://gagnaveita.vegagerdin.is/api/faerd2014_1>. It
does not matter which library I use I always end up with really weird results,
it doesn't parse and the file. Also whenever I try to save the file it doesn't
display like a XML at all. Any idea of how to parse a flie like that?


Answer: When I run this link in browser it shows me XML data.

But when I try to read this in script I get JSON file.

The same when I use `wget` command (on Linux) - I get JSON file.

Maybe you have the same situation.

-

Or maybe browser gets JSON data but it use own method to show it and I get XML
on screen :)

* * *

**EDIT:** I found answer - server check `accept` header. If there is `xml`
then it sends XML file.

Try with and without `headers`

    
    
    import requests
    
    headers = {
       'Accept': 'application/xml',
    }
    
    r = requests.get('http://gagnaveita.vegagerdin.is/api/faerd2014_1', headers=headers)
    
    print(r.content)
    #print(r.json())
    

