HTTPS POST request Python, returning .csv

风格不统一 提交于 2019-12-06 07:57:08

The HTML output with the 302 error is because you're connecting to the site using HTTP instead of HTTPS, which is in your code here:

conn = httplib.HTTPConnection("www.site.com");

Presumably you're doing that because of some other error with the commented out section of your code.

If I were trying to do this I would use Requests, which comes with very clear documentation. With Requests the code would be something like:

import requests

url = "https://www.example.com/nps/servlet/exportdatadownload"
payload = { "val1": "123", "val2": "abc", "val3": "1b3" }
r = requests.post(url, data=payload, verify=True)

The CSV file should be in r.content, which can be written to a file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!