In [3]:
from getpass import getpass
import requests as r
import xml.etree.cElementTree as etree

ns='http://ws.eoddata.com/Data'

In [5]:
username = getpass()


········

In [6]:
password = getpass()


········

In [7]:
ws = 'http://ws.eoddata.com/data.asmx'
call = 'Login'
url = '/'.join((ws, call))

payload = {'Username': username, 'Password': password}

In [8]:
s = r.Session()
resp = s.get(url, params=payload, stream=True)

In [ ]:
# print (resp.content)

In [9]:
root = etree.parse(resp.raw).getroot()

In [10]:
dir(root)


Out[10]:
['__class__',
 '__copy__',
 '__deepcopy__',
 '__delattr__',
 '__delitem__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__len__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__setitem__',
 '__setstate__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'append',
 'clear',
 'extend',
 'find',
 'findall',
 'findtext',
 'get',
 'getchildren',
 'getiterator',
 'insert',
 'items',
 'iter',
 'iterfind',
 'itertext',
 'keys',
 'makeelement',
 'remove',
 'set']

In [21]:
for child in root.getchildren():
    print (child.tag, child.attribute)

In [12]:
for item in root.items():
    print (item)


('Header', 'false')
('Message', 'Login Successful')
('Token', '0185585P0X1S')
('DataFormat', 'MSAI')
('Suffix', 'true')

In [13]:
for key in root.keys():
    print (key)


Header
Message
Token
DataFormat
Suffix

In [14]:
print (root.get('Token'))


0185585P0X1S

In [15]:
print (root.get('Message'))
print (root.get('Token'))
print (root.get('DataFormat'))
print (root.get('Header'))
print (root.get('Suffix'))


Login Successful
0185585P0X1S
MSAI
false
true

In [16]:
resp.status_code


Out[16]:
200

In [17]:
token = root.get('Token')

In [22]:
call = 'ExchangeList'
kwargs = {'Token': token,}

url = '/'.join((ws, call))
resp = s.get(url, params=kwargs, stream=True)

In [24]:
root = etree.parse(resp.raw).getroot()

In [25]:
for item in root.items():
    print (item)


('Source', 'Data.ExchangeList')
('Message', 'Success')
('Date', '2017-01-19T00:02:47.7793906-06:00')

In [ ]:
# for exchange in root2.findall(".//{%s}EXCHANGE" %(ns)):
#     print(
#         exchange.get('Currency'),
#         exchange.get('IntradayStartDate'))
#      print(", ".join([column.text for column in exchange.attrib.items()]))
#     print(exchange.attrib.items())
#     print (exchange.attrib.values())
#     print('"%s"' % '","'.join(exchange.attrib.values()))
    

with open('/home/adrian/test_output.csv', 'w') as f:
    for exchange in root.findall(".//{%s}EXCHANGE" %(ns)):
        f.write('"%s"\n' % '","'.join(exchange.attrib.values()))

In [26]:
exchanges = root.findall(".//{%s}EXCHANGE" %(ns))
tuple(sorted(exchange.get('Code') for exchange in exchanges))


Out[26]:
('AMEX',
 'AMS',
 'ASX',
 'BRU',
 'BSE',
 'CBOT',
 'CFE',
 'CME',
 'COMEX',
 'EUREX',
 'FOREX',
 'HKEX',
 'INDEX',
 'KCBT',
 'LIFFE',
 'LIS',
 'LSE',
 'MGEX',
 'MLSE',
 'NASDAQ',
 'NSE',
 'NYBOT',
 'NYMEX',
 'NYSE',
 'NZX',
 'OTCBB',
 'PAR',
 'SGX',
 'TSX',
 'TSXV',
 'USMF',
 'WCE')

In [27]:
print (root)


<Element '{http://ws.eoddata.com/Data}RESPONSE' at 0x7f7261fa0f98>

In [28]:
for element in root.iter():
    print("%s|%s" % (element.tag, element.attrib))


{http://ws.eoddata.com/Data}RESPONSE|{'Source': 'Data.ExchangeList', 'Message': 'Success', 'Date': '2017-01-19T00:02:47.7793906-06:00'}
{http://ws.eoddata.com/Data}EXCHANGES|{}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2008-01-01T00:00:00', 'Declines': '897', 'LastTradeDateTime': '2017-01-18T16:59:59', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'AMEX', 'IsIntraday': 'true', 'Name': 'American Stock Exchange', 'Advances': '3011'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'AU', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '494', 'LastTradeDateTime': '2017-01-19T00:00:00', 'TimeZone': 'AUS Eastern Standard Time', 'Currency': 'AUD', 'Suffix': 'AX', 'HasIntradayProduct': 'false', 'Code': 'ASX', 'IsIntraday': 'false', 'Name': 'Australian Securities Exchange', 'Advances': '14665'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'IN', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'India Standard Time', 'Currency': 'INR', 'Suffix': 'I', 'HasIntradayProduct': 'false', 'Code': 'BSE', 'IsIntraday': 'false', 'Name': 'Bombay Stock Exchange', 'Advances': '4457'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '234', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Central Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'CBOT', 'IsIntraday': 'true', 'Name': 'Chicago Board of Trade', 'Advances': '101636'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Central Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'CFE', 'IsIntraday': 'true', 'Name': 'Chicago Futures Exchange', 'Advances': '192'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '569', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'CME', 'IsIntraday': 'true', 'Name': 'Chicago Merchantile Exchange', 'Advances': '210889'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'CH', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'EUR', 'Suffix': '', 'HasIntradayProduct': 'false', 'Code': 'EUREX', 'IsIntraday': 'false', 'Name': 'EUREX Futures Exchange', 'Advances': '1772'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'NL', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'EUR', 'Suffix': 'AS', 'HasIntradayProduct': 'false', 'Code': 'AMS', 'IsIntraday': 'false', 'Name': 'Euronext Amsterdam', 'Advances': '150'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'BE', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'EUR', 'Suffix': 'BR', 'HasIntradayProduct': 'false', 'Code': 'BRU', 'IsIntraday': 'false', 'Name': 'Euronext Brussels', 'Advances': '198'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'PT', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'EUR', 'Suffix': 'LS', 'HasIntradayProduct': 'false', 'Code': 'LIS', 'IsIntraday': 'false', 'Name': 'Euronext Lisbon', 'Advances': '52'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'FR', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'EUR', 'Suffix': 'PA', 'HasIntradayProduct': 'false', 'Code': 'PAR', 'IsIntraday': 'false', 'Name': 'Euronext Paris', 'Advances': '1793'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '57', 'LastTradeDateTime': '2017-01-19T00:58:05', 'TimeZone': 'Eastern Standard Time', 'Currency': '', 'Suffix': '', 'HasIntradayProduct': 'false', 'Code': 'FOREX', 'IsIntraday': 'false', 'Name': 'Foreign Exchange', 'Advances': '1128'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '4', 'LastTradeDateTime': '2017-01-19T10:00:00', 'TimeZone': 'Eastern Standard Time', 'Currency': '', 'Suffix': 'IDX', 'HasIntradayProduct': 'false', 'Code': 'INDEX', 'IsIntraday': 'false', 'Name': 'Global Indices', 'Advances': '2898'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'HK', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '700', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Singapore Standard Time', 'Currency': 'HKD', 'Suffix': 'HK', 'HasIntradayProduct': 'false', 'Code': 'HKEX', 'IsIntraday': 'false', 'Name': 'Hong Kong Stock Exchange', 'Advances': '2362'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '21', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Central Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'KCBT', 'IsIntraday': 'true', 'Name': 'Kansas City Board of Trade', 'Advances': '2095'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'false', 'Code': 'LIFFE', 'IsIntraday': 'false', 'Name': 'LIFFE Futures and Options', 'Advances': '2055'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'UK', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '2622', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'GBP', 'Suffix': 'L', 'HasIntradayProduct': 'false', 'Code': 'LSE', 'IsIntraday': 'false', 'Name': 'London Stock Exchange', 'Advances': '37903'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'IT', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '112', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Central European Standard Time', 'Currency': 'EUR', 'Suffix': 'MI', 'HasIntradayProduct': 'false', 'Code': 'MLSE', 'IsIntraday': 'false', 'Name': 'Milan Stock Exchange', 'Advances': '179'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '96', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Central Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'MGEX', 'IsIntraday': 'true', 'Name': 'Minneapolis Grain Exchange', 'Advances': '14993'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '16958', 'LastTradeDateTime': '2017-01-17T00:00:00', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'false', 'Code': 'USMF', 'IsIntraday': 'false', 'Name': 'Mutual Funds', 'Advances': '33996'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2008-01-01T00:00:00', 'Declines': '1837', 'LastTradeDateTime': '2017-01-18T16:59:58', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'NASDAQ', 'IsIntraday': 'true', 'Name': 'NASDAQ Stock Exchange', 'Advances': '5528'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'IN', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '0', 'LastTradeDateTime': '2017-01-19T09:09:00', 'TimeZone': 'GMT Standard Time', 'Currency': 'INR', 'Suffix': 'I', 'HasIntradayProduct': 'false', 'Code': 'NSE', 'IsIntraday': 'false', 'Name': 'National Stock Exchange of India', 'Advances': '1374'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '207', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'NYBOT', 'IsIntraday': 'true', 'Name': 'New York Board of Trade', 'Advances': '88073'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '150', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'COMEX', 'IsIntraday': 'true', 'Name': 'New York Commodity Exchange', 'Advances': '33392'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '237', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'NYMEX', 'IsIntraday': 'true', 'Name': 'New York Merchantile Exchange', 'Advances': '16533'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2008-01-01T00:00:00', 'Declines': '1880', 'LastTradeDateTime': '2017-01-18T16:59:58', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'NYSE', 'IsIntraday': 'true', 'Name': 'New York Stock Exchange', 'Advances': '4691'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'NZ', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '44', 'LastTradeDateTime': '2017-01-19T00:00:00', 'TimeZone': 'New Zealand Standard Time', 'Currency': 'NZD', 'Suffix': 'NZ', 'HasIntradayProduct': 'false', 'Code': 'NZX', 'IsIntraday': 'false', 'Name': 'New Zealand Exchange', 'Advances': '1059'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '2112', 'LastTradeDateTime': '2017-01-18T16:59:59', 'TimeZone': 'Eastern Standard Time', 'Currency': 'USD', 'Suffix': 'OB', 'HasIntradayProduct': 'true', 'Code': 'OTCBB', 'IsIntraday': 'true', 'Name': 'OTC Bulletin Board', 'Advances': '34377'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'SG', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '499', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Singapore Standard Time', 'Currency': 'SGD', 'Suffix': 'SI', 'HasIntradayProduct': 'false', 'Code': 'SGX', 'IsIntraday': 'false', 'Name': 'Singapore Stock Exchange', 'Advances': '12353'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'CA', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '882', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Mountain Standard Time', 'Currency': 'CAD', 'Suffix': 'TO', 'HasIntradayProduct': 'false', 'Code': 'TSX', 'IsIntraday': 'false', 'Name': 'Toronto Stock Exchange', 'Advances': '5418'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'CA', 'IntradayStartDate': '0001-01-01T00:00:00', 'Declines': '562', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Mountain Standard Time', 'Currency': 'CAD', 'Suffix': 'V', 'HasIntradayProduct': 'false', 'Code': 'TSXV', 'IsIntraday': 'false', 'Name': 'Toronto Venture Exchange', 'Advances': '4920'}
{http://ws.eoddata.com/Data}EXCHANGE|{'Country': 'US', 'IntradayStartDate': '2009-01-01T00:00:00', 'Declines': '1', 'LastTradeDateTime': '2017-01-18T00:00:00', 'TimeZone': 'Central Standard Time', 'Currency': 'USD', 'Suffix': '', 'HasIntradayProduct': 'true', 'Code': 'WCE', 'IsIntraday': 'true', 'Name': 'Winnipeg Commodity Exchange', 'Advances': '9999'}

In [29]:
print(etree.tostring(root))


b'<ns0:RESPONSE xmlns:ns0="http://ws.eoddata.com/Data" Date="2017-01-19T00:02:47.7793906-06:00" Message="Success" Source="Data.ExchangeList">\n  <ns0:EXCHANGES>\n    <ns0:EXCHANGE Advances="3011" Code="AMEX" Country="US" Currency="USD" Declines="897" HasIntradayProduct="true" IntradayStartDate="2008-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T16:59:59" Name="American Stock Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="14665" Code="ASX" Country="AU" Currency="AUD" Declines="494" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-19T00:00:00" Name="Australian Securities Exchange" Suffix="AX" TimeZone="AUS Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="4457" Code="BSE" Country="IN" Currency="INR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Bombay Stock Exchange" Suffix="I" TimeZone="India Standard Time" />\n    <ns0:EXCHANGE Advances="101636" Code="CBOT" Country="US" Currency="USD" Declines="234" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="Chicago Board of Trade" Suffix="" TimeZone="Central Standard Time" />\n    <ns0:EXCHANGE Advances="192" Code="CFE" Country="US" Currency="USD" Declines="0" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="Chicago Futures Exchange" Suffix="" TimeZone="Central Standard Time" />\n    <ns0:EXCHANGE Advances="210889" Code="CME" Country="US" Currency="USD" Declines="569" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="Chicago Merchantile Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="1772" Code="EUREX" Country="CH" Currency="EUR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="EUREX Futures Exchange" Suffix="" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="150" Code="AMS" Country="NL" Currency="EUR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Euronext Amsterdam" Suffix="AS" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="198" Code="BRU" Country="BE" Currency="EUR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Euronext Brussels" Suffix="BR" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="52" Code="LIS" Country="PT" Currency="EUR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Euronext Lisbon" Suffix="LS" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="1793" Code="PAR" Country="FR" Currency="EUR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Euronext Paris" Suffix="PA" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="1128" Code="FOREX" Country="US" Currency="" Declines="57" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-19T00:58:05" Name="Foreign Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="2898" Code="INDEX" Country="US" Currency="" Declines="4" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-19T10:00:00" Name="Global Indices" Suffix="IDX" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="2362" Code="HKEX" Country="HK" Currency="HKD" Declines="700" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Hong Kong Stock Exchange" Suffix="HK" TimeZone="Singapore Standard Time" />\n    <ns0:EXCHANGE Advances="2095" Code="KCBT" Country="US" Currency="USD" Declines="21" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="Kansas City Board of Trade" Suffix="" TimeZone="Central Standard Time" />\n    <ns0:EXCHANGE Advances="2055" Code="LIFFE" Country="US" Currency="USD" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="LIFFE Futures and Options" Suffix="" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="37903" Code="LSE" Country="UK" Currency="GBP" Declines="2622" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="London Stock Exchange" Suffix="L" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="179" Code="MLSE" Country="IT" Currency="EUR" Declines="112" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Milan Stock Exchange" Suffix="MI" TimeZone="Central European Standard Time" />\n    <ns0:EXCHANGE Advances="14993" Code="MGEX" Country="US" Currency="USD" Declines="96" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="Minneapolis Grain Exchange" Suffix="" TimeZone="Central Standard Time" />\n    <ns0:EXCHANGE Advances="33996" Code="USMF" Country="US" Currency="USD" Declines="16958" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-17T00:00:00" Name="Mutual Funds" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="5528" Code="NASDAQ" Country="US" Currency="USD" Declines="1837" HasIntradayProduct="true" IntradayStartDate="2008-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T16:59:58" Name="NASDAQ Stock Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="1374" Code="NSE" Country="IN" Currency="INR" Declines="0" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-19T09:09:00" Name="National Stock Exchange of India" Suffix="I" TimeZone="GMT Standard Time" />\n    <ns0:EXCHANGE Advances="88073" Code="NYBOT" Country="US" Currency="USD" Declines="207" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="New York Board of Trade" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="33392" Code="COMEX" Country="US" Currency="USD" Declines="150" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="New York Commodity Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="16533" Code="NYMEX" Country="US" Currency="USD" Declines="237" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="New York Merchantile Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="4691" Code="NYSE" Country="US" Currency="USD" Declines="1880" HasIntradayProduct="true" IntradayStartDate="2008-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T16:59:58" Name="New York Stock Exchange" Suffix="" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="1059" Code="NZX" Country="NZ" Currency="NZD" Declines="44" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-19T00:00:00" Name="New Zealand Exchange" Suffix="NZ" TimeZone="New Zealand Standard Time" />\n    <ns0:EXCHANGE Advances="34377" Code="OTCBB" Country="US" Currency="USD" Declines="2112" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T16:59:59" Name="OTC Bulletin Board" Suffix="OB" TimeZone="Eastern Standard Time" />\n    <ns0:EXCHANGE Advances="12353" Code="SGX" Country="SG" Currency="SGD" Declines="499" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Singapore Stock Exchange" Suffix="SI" TimeZone="Singapore Standard Time" />\n    <ns0:EXCHANGE Advances="5418" Code="TSX" Country="CA" Currency="CAD" Declines="882" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Toronto Stock Exchange" Suffix="TO" TimeZone="Mountain Standard Time" />\n    <ns0:EXCHANGE Advances="4920" Code="TSXV" Country="CA" Currency="CAD" Declines="562" HasIntradayProduct="false" IntradayStartDate="0001-01-01T00:00:00" IsIntraday="false" LastTradeDateTime="2017-01-18T00:00:00" Name="Toronto Venture Exchange" Suffix="V" TimeZone="Mountain Standard Time" />\n    <ns0:EXCHANGE Advances="9999" Code="WCE" Country="US" Currency="USD" Declines="1" HasIntradayProduct="true" IntradayStartDate="2009-01-01T00:00:00" IsIntraday="true" LastTradeDateTime="2017-01-18T00:00:00" Name="Winnipeg Commodity Exchange" Suffix="" TimeZone="Central Standard Time" />\n  </ns0:EXCHANGES>\n</ns0:RESPONSE>'

In [30]:
dir(exchange.attrib)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-30-43d62690c9b7> in <module>()
----> 1 dir(exchange.attrib)

NameError: name 'exchange' is not defined

In [65]:
s.close()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-65-0469e1c57dbb> in <module>()
----> 1 s.close()

AttributeError: 'str' object has no attribute 'close'