Wikidata-Toolkit
Wikidata-Toolkit copied to clipboard
CSRF Token error
Dear friends,
I have been working with wikidata for sometime, but since last week , when I try to make a bulk load, I receive a CSRF error.
I mean, when I edit wikidata and write the item, I do not receive any error message and write the item, but now I receive a CSRF Token error message as shown below:
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
Exception in thread "main" 2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
2019-09-23 09:12:42 ERROR - Gave up after several retries. Last error was: org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
org.wikidata.wdtk.wikibaseapi.apierrors.TokenErrorException: [badtoken] Invalid CSRF token.
at org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorHandler.throwMediaWikiApiErrorException(MediaWikiApiErrorHandler.java:55)
at org.wikidata.wdtk.wikibaseapi.ApiConnection.checkErrors(ApiConnection.java:466)
at org.wikidata.wdtk.wikibaseapi.ApiConnection.sendJsonRequest(ApiConnection.java:406)
at org.wikidata.wdtk.wikibaseapi.WbEditingAction.performAPIAction(WbEditingAction.java:716)
at org.wikidata.wdtk.wikibaseapi.WbEditingAction.wbEditEntity(WbEditingAction.java:294)
at org.wikidata.wdtk.wikibaseapi.WikibaseDataEditor.createItemDocument(WikibaseDataEditor.java:240)
at wikiloader.GLEIFRegisterResponsibleLoader.main(GLEIFRegisterResponsibleLoader.java:743)
Any idea why is that happening?, is it a coding error?, or it is another kind of error?
Luis Ramos
@Tpt @wetneb Is this still broken? I remember from when I used Wikibase API directly that CSRF tokens expire when not used for some time. They have to be renewed periodically. This is not a problem for busy bots, but assisted editing tools will have gaps in activity that cause CSRF tokens to expire.
I solved the issue, thans
@luisenriqueramos1977 So what was the cause and how did you solve the problem? Can this issue be closed?
Hi, I see this is an old issue, but I recently have also ran into this problem. For me it occurs when I try to login again after I caught an AssertUserFailedException. After debugging I think the issue is that the login method of BasicApiConnection does not have a way to reset the login token or clear the token from outside of the package.
The login method calls getOrFetchToken, but the token map is already filled from the first login. However, this token is expired. I think there should be a way to force token fetching in this case. I am however intrigued how @luisenriqueramos1977 solved the issue.
dear @robertvazan , yes you can close it, but @Lhaaits unfortunately I do not remember how I solved it that time.
I'd like to make a pull request to enable resetting the tokens, if that's ok, so maybe you can leave it open until then
I think this can be closed. Could someone with rights create a release for https://github.com/Wikidata/Wikidata-Toolkit/pull/765 ?
@robertvazan could you create a release for https://github.com/Wikidata/Wikidata-Toolkit/pull/765?
@Lhaaits Hi. I am not currently actively working on WDTK for lack of time. I think releases are done by either @Tpt or @wetneb.
I am not actively working on this project either. @Lhaaits you have made multiple contributions already, would you like to help with reviewing PRs and making releases? Unless @robertvazan or @Tpt see a problem with this, I would invite you to the repository so that you can do that.
Hi @wetneb, I think my invitation expired a while ago, could you send a new one?
Invite sent again, please go to https://github.com/Wikidata/Wikidata-Toolkit to accept it