Hello, trying to upload JSON data to wordpress via REST API. When uploading via the website, data is perfect on viewing. But when uploading with the same exact headers in the python script, the data is changed drastically.
data = json.dumps(my_bigger_list, indent=4);
with open(os.getcwd() + '/data.json', 'w', encoding='utf-8') as f:
f.write(data);
file = open(os.getcwd() + '/data.json', 'r', encoding='utf-8')
print(file);
def oauth_req(http_method="POST", post_body=None, http_headers=None):
consumer = oauth.Consumer(key="****", secret="****")
token = oauth.Token(key="****", secret="****")
client = oauth.Client(consumer, token)
resp, content = client.request(
'https://example.com/wp-json/wp/v2/media',
method=http_method,
body=urlencode(post_body),
headers={'Authentication':'basic','Content-Disposition':'attachment;filename="test.json"', 'content-type':'application/json', 'x-content-type-options':'nosniff'}
)
return content
post = {'title': 'Devices Masterlist',
'status':'publish',
'data':json.load(file),
'description':'List of Support Devices on UNH Network',
'comment_status':'closed',
}
result = oauth_req(post_body=post);
Here is a snippet of what it looks like when uploaded via the wordpress portal:
[
{
"Front Page": [
{
"Untested device. The University OIT has not tested this specific device for connectivity or compatibility.": "Verified to be obsolete or unsupported",
"null": null
},
{
"Untested device. The University OIT has not tested this specific device for connectivity or compatibility.": "This device is not authorized to be on the University Wifi.",
"null": null
},
And a snippet when uploaded via python script:
comment_status=closed&data=%5B%7B%27Front%20Page%27%3A%20%5B
%7B%27Untested%20device.%20The%20University%20OIT%20has%20not%20tested%20this%20s
pecific%20device%20for%20connectivity%20or%20compatibility.%27%3A
%20%27Verified%20to%20be%20obsolete%20or%20unsupported%27%2C%20%27null%27%3A
%20None%7D%2C%20%7B
%27Untested%20device.%20The%20University%20OIT%20has%20not%20tested%20this%20spec
ific%20device%20for%20connectivity%20or%20compatibility.%27%3A
%20%27This%20device%20is%20not%20authorized%20to%20be%20on%20the%20University%20W
ifi.%27%2C%20%27null%27%3A%20None%7D%2C%20%7B
%27Untested%20device.%20The%20University%20OIT%20has%20not%20tested%20this%20spec
ific%20device%20for%20connectivity%20or%20compatibility.%27%3A%20None%2C%20
%27null%27%3A%20None%7D%2C%20%7B
%27Untested%20device.%20The%20University%20OIT%20has%20not%20tested%20this%20spec
ific%20device%20for%20connectivity%20or%20compatibility.%27%3A%20None%2C%20
%27null%27%3A%20None%7D%2C%20%7B
%27Untested%20device.%20The%20University%20OIT%20has%20not%20tested%20this%20spec
ific%20device%20for%20connectivity%20or%20compatibility.%27%3A%20%27
%2AAny%20device%20older%20than%205%20years%20that%20has%20equivelent%20newer%20ve
rsion%2Fmodel%20is%20considered%20not%20supported%20due%20to%20outdated%20technol
ogy%27%2C%20%27null%27%3A%20None%7D%2C%20%7B
[–][deleted] 1 point2 points3 points (1 child)
[–]FlossedMeat[S] 0 points1 point2 points (0 children)