How to fetch an XML file using an HTTPS query

Ido Levy IDOL at il.ibm.com
Tue Aug 4 07:25:17 EDT 2009


Hello All 

I am quite new to Python and I would appreciate your advice on the 
following issue.

I am trying to fetch an XML file from a remote server using an HTTPS 
query.

When testing the HTTPS query from the browser after I entered the URL I 
got a pop-up box asking me if I want to "save a file" or "open with".
>From a Python script I tried using urllib but it fails.

I validated that my Python release support https request by using the 
following code and a different URL:
        import urllib
        print urllib.urlopen('https://...').read()
and got the expected result.


When I tried the above code or the following one with the URL that should 
return an XML file 
        import sys
        import urllib
        import urllib2

        headers = {'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; 
rv:1.7.12) Gecko/20050923 Firefox/1.0.7', 'Cookie': 
'JSESSIONID=000000000000000000000000000:111111111;Path=/',}
        url = "https://..."
        req = urllib2.Request(url, None, headers)
        urlFH = urllib2.urlopen(req)
        headers = urlFH.info()
        page_content = urlFH.readlines()
        urlFH.close()

        for line in page_content:
                print 'line: %s' % line


I got the following result in both cases:
        <?xml version="1.0"?>
        <Devices>
        <Error>Invalid filter passed.</Error>
        </Devices>


Thanks in Advance

Ido Levy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090804/0ccb5da4/attachment.html>


More information about the Python-list mailing list