I am trying to upload a video through the django admin site using python requests. I am logging in just fine:
import requests
login_url = "http://127.0.0.1:8000/admin"
client = requests.client()
csrftoken = client.cookies['csrftoken']
login_data = {'username': 'username', 'password': 'password',
'this_is_the_login_form': '1',
'csrfmiddlewaretoken': csrftoken
}
r = client.post(login_url, data=login_data)
After logging in I pull the page where I will upload a (video) file:
target_url = "http://127.0.0.1:8000/admin/product/700/"
r = client.get(target_url)
In the HTML I have a script(That is not being pulled in with the .get() request) to listen when a file has been uploaded:
var object_id = 700;
$(document).ready(function() {
// Upload button handler
$('.file').on('change', handleFileSelect);
...
I have tried setting the file to the object I'm trying to upload, and making another get request hoping the file argument will be set, thus make the script fire and start the upload process.
<input id="file" class="file" type="file" name="file">
data = {'file': open('file.flv', 'rb')}
r = client.get(target_url, data=data)
How do I make a request to the target_url, pull down the upload script, and make the upload script fire in order to upload the file?