Elaphus
Elaphus

Reputation: 1

Submitting time data to wikibase with `wbcreateclaim` results in "invald-snak" error

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:

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:

Upvotes: 0

Views: 126

Answers (1)

Elaphus
Elaphus

Reputation: 1

It works if the value string is generated from the dictionary via json.dumps().

Upvotes: 0

Related Questions