title: Xml parsing from web response
body: <p>I'm trying to get response from nominatim to geo-code few thousands of cities. </p>
  
  <pre><code>import os
  import requests
  import xml.etree.ElementTree as ET
  
  txt = open('input.txt', 'r').readlines()
  for line in txt:
   lp, region, district, municipality, city = line.split('\t')
   baseUrl = 'http://nominatim.openstreetmap.org/search/gb/'+region+'/'+district+'/'+municipality+'/'+city+'/?format=xml' 
   # eg. http://nominatim.openstreetmap.org/search/pl/podkarpackie/stalowowolski/Bojan%C3%B3w/Zapu%C5%9Bcie/?format=xml
   resp = requests.get(baseUrl)
   resp.encoding = 'UTF-8' # special diacritics
   msg = resp.text
   # parse response to get lat &amp; long
   tree = ET.parse(msg)
   root = tree.getroot()
   print tree
  </code></pre>
  
  <p>but the result is:</p>
  
  <pre><code>Traceback (most recent call last):
  File "geo_miasta.py", line 17, in &lt;module&gt;
      tree = ET.parse(msg)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1182, in parse
      tree.parse(source, parser)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 647, in parse
      source = open(source, "rb")    
  IOError: [Errno 2] No such file or directory: u'&lt;?xml version="1.0" encoding="UTF-8" ?&gt;\n&lt;searchresults timestamp=\'Tue, 11 Feb 14 21:13:50 +0000\' attribution=\'Data \xa9 OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright\' querystring=\'\u015awierczyna, Drzewica, opoczy\u0144ski, \u0142\xf3dzkie, gb\' polygon=\'false\' more_url=\'http://nominatim.openstreetmap.org/search?format=xml&amp;amp;exclude_place_ids=&amp;amp;q=%C5%9Awierczyna%2C+Drzewica%2C+opoczy%C5%84ski%2C+%C5%82%C3%B3dzkie%2C+gb\'&gt;\n&lt;/searchresults&gt;'
  </code></pre>
  
  <p>What is wrong with this?</p>
  
  <p>Edit:
  Thant to @rob my solution is:</p>
  
  <pre><code>#! /usr/bin/env python2.7
  # -*- coding: utf-8 -*-
  
  import os
  import requests
  import xml.etree.ElementTree as ET
  
  txt = open('input.txt', 'r').read().split('\n')
  
  for line in txt:
      lp, region, district, municipality, city = line.split('\t')
      baseUrl = 'http://nominatim.openstreetmap.org/search/pl/'+region+'/'+district+'/'+municipality+'/'+city+'/?format=xml'
      resp = requests.get(baseUrl)
      msg = resp.content
      tree = ET.fromstring(msg)
      for place in tree.findall('place'):
      location = '{:5f}\t{:5f}'.format(
          float(place.get('lat')),
          float(place.get('lon')))
  
      f = open('result.txt', 'a')
      f.write(location+'\t'+region+'\t'+district+'\t'+municipality+'\t'+city)
      f.close()
  </code></pre>