0

I'm trying in python2.7 with xmltodict ext. get data from app engine API (XML type). Got no idea of how doing that... I tried to do so with local XML (I download it from source url) with success my local code look like this:

import xmltodict

document = open("my local path\API_GETDATA.xml", "r")

read_doc = document.read()

xml_doc = xmltodict.parse(read_doc)

for i in xml_doc:

    print (xml_doc[i])

    i=i+1

and my result is printing all XML fields.

How can I make it work on url? Is there any other thing I miss?

Tzahi Kadosh
  • 397
  • 2
  • 9
  • 21

1 Answers1

4

Use the python library requests:

Install with pip install requests and use like this:

import requests

r = requests.get("url")

xmltodict.parse(r.content)
Simon Kirsten
  • 2,542
  • 18
  • 21
  • i'm getting error msg : Traceback (most recent call last): File "C:\Users\tzahi.k\Desktop\xmltodict-0.10.2\tttt.py", line 18, in xmltodict.parse(r.content) File "C:\Users\tzahi.k\Desktop\xmltodict-0.10.2\xmltodict.py", line 311, in parse parser.Parse(xml_input, True) ExpatError: syntax error: line 1, column 0 – Tzahi Kadosh Jun 15 '16 at 07:19
  • It seems like either the XML is not proper XML or some other XML parsing problem. To debug this write the following before the parse line: `open("out.txt", "wb").write(r.content)` and upload the out.txt file to pastebin.com and post it here. I will take a look at it. – Simon Kirsten Jun 15 '16 at 08:29