.csvファイルで応答する必要があるHTTPSサイトにPOSTリクエストを送信したいと思います。私はこのPythonコードを持っています:
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()
しかし、エラーが発生しています:
BadStatusLine: '' (in httplib.py)
Chrome拡張機能:高度なRESTクライアント(スクリーンショット)でPOSTリクエストを試しましたが、正常に機能します。
何が問題で、どうすれば解決できますか?(HTTPSのせいですか?)
編集、リファクタリングされたコード:
try:
#conn = httplib.HTTPSConnection(host="www.site.com", port=443)
=>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]
出力:
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>
私は何が間違っているのですか?