I can add a .csv file efficiently within the dashboard, however after I attempt to use Python + WP REST API, I get the next error:
{'code': 'rest_upload_sideload_error', 'message': 'Sorry, you aren't allowed to add this file sort.', 'information': {'standing': 500}}
My Python code is as follows:
person="myusername"
password = 'xyz'
url="http://localhost/enigma/wp-json/wp/v2/media"
creds = person + ':' + password
# print(creds)
token = base64.b64encode(creds.encode())
csvname = "CSV File"
csvpath = "Weekly Highlightscsv-exportshisorical_prices.csv"
csvbytes = {'file': open(csvpath, 'rb')}
header = {'Authorization': 'Primary ' + token.decode('utf-8'), "Settle for": "utility/json", "Content material-type": "textual content/csv", 'Content material-Disposition': "attachment; filename=%s" % csvname,}
submit = requests.submit(url, headers=header, recordsdata=csvbytes)
print(submit.json())
Any assist can be significantly appreciated!
I’ve tried the entire on-line options, resembling including the next to my features.php file:
operate my_theme_custom_upload_mimes( $existing_mimes ) {
// Add webm to the record of mime sorts. $existing_mimes['webm'] = 'video/webm';
// Return the array again to the operate with our added mime sort.
$existing_mimes['csv'] = 'textual content/csv';
return $existing_mimes;
}
add_filter( 'mime_types', 'my_theme_custom_upload_mimes' );
I’ve additionally added this to my wp-config file:
outline( 'ALLOW_UNFILTERED_UPLOADS', true );
And I even have put in a plugin to permit CSV file sorts to be uploaded.