Closed traopia closed 2 weeks ago
Hello @traopia , do you have a code example and/or the wikidata entity you are trying to import?
yes!
CODE:
def copy_entity_wikibase_with_property(entity_id, property_id, value_id):
"""entity_id = wikidata entity id
property_id = wikibase property id
value_id = wikibase value id"""
failed_entities = []
try:
# Fetch the entity from Wikidata
entity = wbi.item.get(entity_id, mediawiki_api_url='https://www.wikidata.org/w/api.php', login=login_wikidata)
# Prepare the entity for writing to the new Wikibase instance
entity.claims = Claims() # Ensure claims are correctly processed if needed
statement = Item(value=value_id, prop_nr=property_id)
# Add the new statement to the entity
entity.claims.add(statement)
# Attempt to write the entity to the new Wikibase instance
entity.write(mediawiki_api_url='https://fashion.wikibase.cloud/w/api.php', login=login_testwikidata, as_new=True)
print(entity_id)
except Exception as e:
# Log the error and add the entity ID to the list of failed entities
failed_entities.append(entity_id)
pass
return failed_entities
EXAMPLE USAGE WHERE IT WORKS copy_entity_wikibase_with_property('Q1891','P6','Q930') EXAMPLE WHERE IT DOESNT WORK copy_entity_wikibase_with_property('Q159','P6','Q930')
Thank you for your help!
I tried to reproduce your issue, without success. I've a slightly more precise error message because the "ak" language doesn't exist on my Wikibase instance.
My issue is located, on the two entity, with the "ak" label, which doesn't exist anymore so you can't import it in new wikibase instance.
Which version of Mediawiki and Wikibase do you use?
Only keep the English labels, and explicitly removing all the other languages worked!
ex:
` entity = wbi.item.get(wikidata_id, mediawiki_api_url=wikidata_api_url, login=login_wikidata)
entity.sitelinks.sitelinks.clear()
entity.aliases.aliases.clear()
en_description = entity.descriptions.get('en').value
en_label = entity.labels.get('en').value
entity.labels = Labels()
entity.descriptions = Descriptions()
entity.aliases = Aliases()
entity.labels.set('en',en_label)
entity.descriptions.set('en', en_description)`
Hi! I have this error for several entities that I am trying to import from wikidata:
wikibaseintegrator.wbi_exceptions.MWApiError: 'The supplied language code was not recognized.'
Or the following error:
wikibaseintegrator.wbi_exceptions.ModificationFailed: 'Label and and description for language code ta can not have the same value.'
How can I deal with this? They are quite a common errors (at least in my experience so far) so I guess there must be a way around. Thank you!