Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import entity from wikidata errors: wikibaseintegrator.wbi_exceptions.MWApiError: 'The supplied language code was not recognized.' #752

Open
traopia opened this issue Aug 7, 2024 · 3 comments
Assignees

Comments

@traopia
Copy link

traopia commented Aug 7, 2024

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!

@traopia traopia changed the title import entity from wikidata import entity from wikidata errors: wikibaseintegrator.wbi_exceptions.MWApiError: 'The supplied language code was not recognized.' Aug 7, 2024
@LeMyst
Copy link
Owner

LeMyst commented Aug 7, 2024

Hello @traopia , do you have a code example and/or the wikidata entity you are trying to import?

@traopia
Copy link
Author

traopia commented Aug 9, 2024

yes!

  1. For the first example, I am trying to import a wikidata entity into my wiki base and add a statement (based on my wiki base to it). It works for many entities, but for some it doesn't and give the error: "The supplied language code was not recognized."

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')

  1. For the second error I think I found a fix: which is simply adding a space to the description imported - so that it doesn't match with the label.

Thank you for your help!

@LeMyst
Copy link
Owner

LeMyst commented Aug 9, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants