Warm tip: This article is reproduced from serverfault.com, please click

Simple xml-request (GET)

发布于 2020-11-30 18:06:22

I got an url and a some header-data - which, so I've been told, are necessary:

url = "sample_url"
Content-Type: application/xml;charset=UTF-8
Accept: application/xml;charset=UTF-8

With the sample-url I want to create a GET request and receive xml-data via python but don't know which is currently the best way to do that!

Might someone give me advice or example?

Questioner
finethen
Viewed
0
Omri Shayo 2020-12-01 02:10:39

Try using requests library:

url = 'sample_url'
headers = {'Content-Type': 'application/xml;charset=UTF-8', 'Accept': 'application/xml;charset=UTF-8'}
r = requests.get(url, headers=headers)
xml = r.text