I am currently trying to populate a wikidata instance via POST requests. For this purpose I use the requests
library in Python together with the MediaWiki API.
So far I managed to create claims with different datatypes (like String
, Quantity
, Wikidata items
, Media
...). The general scheme I use is this (with different value
strings for each datatype):
import requests
session = requests.Session()
# authenticate and obtain a csrf_token
parameters = {
'action': 'wbcreateclaim',
'format': 'json',
'entity': 'Q1234',
'snaktype': 'value',
'property': 'P12',
'value': '{"time": "+2022-02-19T00:00:00Z", "timezone": 0, "precision": 11, "calendarmodel": "http://www.wikidata.org/entity/Q1985727"}',
'token': csrf_token,
'bot': 1,
}
r = session.post(api_url, data=parameters)
print(r.json())
Every attempt to insert data of type time
leads to an invalid-snak
error (info: "invalid snak data.").
The following changes did not solve the problem:
before
and after
keys in the dictionary,timezone
, precision
, calendarmodel
and combinations thereof,time
string as 2022-02-19
,Do you know, what I'm doing wrong here? What must the value
field look like?
I am aware of the fact that special libraries or interfaces for exist for these tasks. But I do want to use the Wikidata API directly with the requests
library in Python.
Thank you very much for your help!
Installed software versions:
It works if the value string is generated from the dictionary via json.dumps()
.