Reputation: 6869
I am using the Python requests package to download a CSV file. I am successfully navigating a webpage via Python but am stuck on the final stage of downloading the file. I am redirected here and the html looks (something )like this:
<html>
<body>
<form action='/export_data_test/convertxl.aspx' method='get'>
<input type='hidden' name='SID' value='[email protected]'>
</form>
<script>window.onload = function() {document.forms[0].submit();}</script>
</body>
</html>
I am use to submitting forms that use the POST method but I see that GET is being used. Additionally, this page is automatically submitting the form "onload" and so the the browser normally downloads it immediately. It isn't clear how to capture this using the Python requests package.
I've tried:
session.get(domain+"/export_data_test/convertxl.aspx", data=payload, allow_redirects=True, verify=certifi.where())
However, this returns a response that contains no content (I expect a CSV file). Again, the behavior through the browser is that a file is downloaded.
Upvotes: 1
Views: 1692
Reputation: 6869
In case others make the same mistake as I did, the get
method takes in params
as an argument and not data
(which is used for the post
method). So, the correct way of sending the payload is as shown:
session.get(domain+"/export_data_test/convertxl.aspx",
params=payload,
allow_redirects=True,
verify=certifi.where())
Upvotes: 1