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?

1
  • What is not working? Commented Jun 13, 2016 at 12:35

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

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 <module> 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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.