[英]python requests - file upload not working
I'm having a heck of a time getting this to work. 我很难过要开始工作了。 The form code... 表单代码...
<div bran="uplo">
<form name="uplo" method="post" enctype="multipart/form-data" action="upload.aspx">
<input type="hidden" name="proc" value="wagr"/>
<span>Data File:</span>
<span>
<input type="file" name="wagr"/>
</span>
</form>
<span>
<button onclick="document.uplo.submit();">Upload</button>
</span>
</div>
Here's the 356th version of the code I've tried... 这是我尝试过的代码的第356版...
url = 'https://www.example.com/upload.aspx'
files = {'file':('data.txt', open('data.txt', 'rb'))}
data = {'proc':'wagr'}
r = requests.post(url, files=files, data=data)
All that seems to happen when I look at r.content
is the page itself and that is all. 当我查看r.content
时,似乎所发生的r.content
就是页面本身,仅此r.content
。
I asked for permission here is the actual form... 我要求许可的是实际表格...
https://dfu.xb-online.com/wagerupload/betupload.aspx https://dfu.xb-online.com/wagerupload/betupload.aspx
First, check your post. 首先,检查您的帖子。
------WebKitFormBoundaryJQcvwSzBape4lDoO
Content-Disposition: form-data; name="proc"
wagr
------WebKitFormBoundaryJQcvwSzBape4lDoO
Content-Disposition: form-data; name="wagr"; filename="test.py"
Content-Type: text/x-python
------WebKitFormBoundaryJQcvwSzBape4lDoO--
This is mine, you can see, name
for file should be wagr
. 您可以看到这是我的,文件name
应为wagr
。
Second, check your response. 其次,检查您的回应。
Actually, it will return a page but contains more information based on the file you uploaded. 实际上,它将返回一个页面,但包含基于您上载的文件的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.