I want to make an email request to an HTTPS site that should respond with a CSV file. I have this Python code:
url = 'https://www.site.com/servlet/datadownload' values = { 'val1' : '123', 'val2' : 'abc', 'val3' : '1b3', } data = urllib.urlencode(values) req = urllib2.Request(url,data) response = urllib2.urlopen(req) myfile = open('file.csv', 'wb') shutil.copyfileobj(response.fp, myfile) myfile.close()
But we get the error:
BadStatusLine: '' (in httplib.py)
I tried the mail request with the Chrome Extension: Advanced REST client (screenshot) and it works great.
What could be the problem and how can I solve it? (is this related to https?)
EDIT Reorganized Code:
try: #conn = httplib.HTTPSConnection(host="www.site.com", port=443)
=> Gives BadStatusLine: '' error BadStatusLine: ''
conn = httplib.HTTPConnection("www.site.com"); params = urllib.urlencode({'val1':'123','val2':'abc','val3':'1b3'}) conn.request("POST", "/nps/servlet/exportdatadownload", params) content = conn.getresponse() print content.reason, content.status print content.read() conn.close() except: import sys print sys.exc_info()[:2]
Output:
Found 302 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>302 Found</TITLE> </HEAD><BODY> <H1>Found</H1> The document has moved <A HREF="https://www.site.com/nps/servlet/exportdatadownload">here</A>.<P> <HR> <ADDRESS>Oracle-Application-Server-10g/10.1.3.5.0 Oracle-HTTP-Server Server at mp-www1.mrco.be Port 7778</ADDRESS> </BODY></HTML>
What am I doing wrong?
francisMi
source share