# -*- coding: utf-8  -*-
import pywikibot
import json
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()

def set_active(politican_item_id):
    item = pywikibot.ItemPage(repo, politican_item_id)
    claims = item.get()['claims']['P39']

    # Q17781726 is: Mitglied des Lantags Nordrhein-Westfahlen
    landtag_membership = next(claim for claim in claims if claim.target.id == 'Q17781726')


    qualifier = pywikibot.Claim(repo, u'P582')
    qualifier.setSnakType('novalue')  # No end date, this is still their current position
    landtag_membership.addQualifier(qualifier)

    item.editEntity(summary='pyWikibot test edit')
    
set_active(u"Q1157242")
WARNING: API error modification-failed: The statement has already a qualifier with hash f148a727ee614bf2862cfc5c4730f50936c281de
---------------------------------------------------------------------------
APIError                                  Traceback (most recent call last)
<ipython-input-1-5082b06565e3> in <module>()
     19     item.editEntity(summary='pyWikibot test edit')
     20 
---> 21 set_active(u"Q1157242")

<ipython-input-1-5082b06565e3> in set_active(politican_item_id)
     15     qualifier = pywikibot.Claim(repo, u'P582')
     16     qualifier.setSnakType('novalue')  # No end date, this is still their current position
---> 17     landtag_membership.addQualifier(qualifier)
     18 
     19     item.editEntity(summary='pyWikibot test edit')

/srv/paws/pwb/pywikibot/page.py in addQualifier(self, qualifier, **kwargs)
   4734         @type qualifier: Claim
   4735         """
-> 4736         data = self.repo.editQualifier(self, qualifier, **kwargs)
   4737         qualifier.isQualifier = True
   4738         self.on_item.latest_revision_id = data['pageinfo']['lastrevid']

/srv/paws/pwb/pywikibot/site.py in callee(self, *args, **kwargs)
   1328             else:
   1329                 raise Exception("Not implemented")
-> 1330             return fn(self, *args, **kwargs)
   1331 
   1332         if not __debug__:

/srv/paws/pwb/pywikibot/site.py in editQualifier(self, claim, qualifier, new, bot, summary, baserevid)
   7493 
   7494         req = self._simple_request(**params)
-> 7495         data = req.submit()
   7496         return data
   7497 

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2187                               % result)
   2188 
-> 2189                 raise APIError(**result['error'])
   2190             except TypeError:
   2191                 raise RuntimeError(result)

APIError: modification-failed: The statement has already a qualifier with hash f148a727ee614bf2862cfc5c4730f50936c281de [help:See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]