I'm trying to read an XML file from a web address and write that file to a Sql Server DB as an XML data-type. I don't want to do any parsing of the XML, just write it like a string to the database. I will be using it to take snapshots every few hours and then use Sql to deal with the information as an XML datatype.
I'm currently receiving below mentioned error:
'IOError: [Errno socket error] [Errno 11001] getaddrinfo failed'
I'm not sure I'm reading the xml file properly (as one single piece of information) - Any suggestions?
import pyodbc
import urllib
xmlpath = "http://www.w3schools.com/xml/cd_catalog.xml"
xmlurl= urllib.urlopen(xmlpath)
xml_as_string = xmlurl.read()
cnxn = pyodbc.connect(
'Trusted_Connection=yes;
DRIVER={SQL Server};
SERVER=servername;
DATABASE=database_name;
UID=user;
PWD=pass'
)
cursor = cnxn.cursor()
cursor.execute("insert into table values ('Text', 1, '"+ xml_as_string +"')")
cnxn.commit()