我编写了以下代码,该代码应该使用请求将图像上传到名为Roblox的网站。
import requests
s = requests.session()
login_data = dict(username='USERNAMEHERE', password='PASSWORDHERE')
s.post('https://www.roblox.com/newlogin', data=login_data)
upload_data = dict(name="PythonUpload")
r = s.post('http://www.roblox.com/build/upload', files={'file': open('PythonDecalUploadTest.jpg', 'rb')}, data=upload_data)
print(r) #This returns a 500 error
这是发布到的表单。
<form action="/build/upload" enctype="multipart/form-data" id="upload-form" method="post">
<input name="__RequestVerificationToken" type="hidden" value="H_69BCzd4bdyJ7EXalAOvaa-zeZZOvtQR-E9YHnCpmH9HVZKxHGrSVjAciLInCibyD8k432ZRzqX8d0MPPfCv-vOfAM1">
<input id="assetTypeId" name="assetTypeId" type="hidden" value="13">
<input id="isOggUploadEnabled" name="isOggUploadEnabled" type="hidden" value="True">
<input id="groupId" name="groupId" type="hidden" value="">
<input id="onVerificationPage" name="onVerificationPage" type="hidden" value="False">
<div id="container">
<div class="form-row">
<label for="file">Find your image:</label>
<input id="file" type="file" name="file" tabindex="1">
<span id="file-error" class="error"></span>
</div>
<div class="form-row">
<label for="name">Decal Name:</label>
<input id="name" type="text" class="text-box text-box-medium" name="name" maxlength="50" tabindex="2">
<span id="name-error" class="error"></span>
</div>
<div class="form-row submit-buttons">
<a id="upload-button" class="btn-medium btn-primary btn-level-element " tabindex="3">Upload</a>
<span id="loading-container">
<img src="http://images.rbxcdn.com/ec4e85b0c4396cf753a06fade0a8d8af.gif">
</span>
</div>
</div>
</form>
我不确定请求验证令牌是什么,因此我只是更改了几个字母/数字以防万一。
那为什么这会返回500错误?为什么不上传我的图片?