This forum is now read-only. Please use our new forums at discuss.codecademy.com.

329 points
93ccc7664e35b2b1607890f8e6ae83df?s=140&d=retro
Submitted by
nclee
about 3 years ago

Why does the code in exercises 20 to 22 not write to xml file?

This question has been asked but there has not been a definite answer to the problem yet.

Why does my code pass in exercises 20 to 22 however nothing is written to the xml file?
Is there a problem in my code or a bug and or problem in Codecademy here?

When I open the xml file my_feed after running the script it just remains with the code from the python script.

Again I can run the following code with no errors and codecademy says the code is correct, however nothing seems to pass to the xml file.

from urllib2 import urlopen
from urllib import quote

key = "API_KEY"
url = 'http://api.npr.org/query?apiKey='
url += key
url += "&numResults=3&action=Or&requiredAssets=audio&format=Podcast"

npr_id = raw_input("Enter comma-separated NPR IDs or leave blank.")
search_string = raw_input("Enter your search string or leave blank.")
feed_title = raw_input("What's your feed title?")

if npr_id or search_string:
    raw_input("Hit Enter to download your podcast.")

    if npr_id:
        url += "&id=" + npr_id
    if search_string:
        url += "&searchterm=" + quote(search_string)
    if feed_title:
        url += "&title=" + quote(feed_title)

    response = urlopen(url)
    output = response.read()
    my_feed = open('my_feed.xml', 'w')
    my_feed.write(output)
    my_feed.close()

else:
    print "You must enter an NPR ID, a search term, or both."