我正在尝试使用urllib填写表单,然后从提交的数据中检索结果。我要发布到的应用程序位于服务器上,我必须通过appgate登录才能访问。 POST表单(我在终端的响应中看到)是这样的:
<form action="accuracy-upload3" method="post"
enctype="multipart/form-data">
Human: <input type="file" id="human" name="human"><br>
Machine: <input type="file" id="machine" name="machine"><br>
<input type="submit" class="submit" value="Submit" />
</form>
但是,即使该方法是“ POST”,我似乎也正在执行GET,因为返回的是url的html,而不是返回来自url的'action'参数的响应。我的代码如下:
url = "https://accuracy3.html"
filename1 = 'human.txt'
filename2 = 'machine.txt'
filedata1 = open(filename1).read()
filedata2 = open(filename2).read()
values = {
"Human": filedata1,
"id": "human",
"name": "human",
"Machine": filedata2,
"id": "machine",
"name": "machine",
"value": "Submit"
}
req = urllib2.Request(url, data = urllib.urlencode(values), headers
=
{"Content-type": "application/x-www-form-urlencoded"})
response = urllib2.urlopen(req)
print response.read()
在Making a POST call instead of GET using urllib2中,由于我已经发送了数据,因此它应该发送POST,但是它没有这样做。
谁能看到我的脚本出了什么问题?