**Steps to replicate the issue** (include links if applicable):
Not sure. I encounter the issue when uploading files using pywikibot. Notably, I toggled on asynchronous=True. The following code snippet is used:
```
site.upload(
source_filename=filename,
filepage=FilePage(site, pagename),
text=text,
comment=comment,
asynchronous=size > 256 * 1024 * 1024,
chunk_size=32 * 1024 * 1024,
ignore_warnings=["was-deleted"],
)
```
**What happens?**:
pywikibot keeps logging the following lines without throwing an error or returning:
```
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 09:14:44
```
**What should have happened instead?**:
Either:
a. It refreshes the CSRF token automatically and retry.
b. It throws an exceptions.
c. It returns `False` to indicate a failure.
**Software version** (skip for WMF-hosted wikis like Wikipedia):
pywikibot/8.3.0
Wikimedia Commons
**Other information** (browser name/version, screenshots, etc.):
Logs:
```
INFO:__main__:PDF for REDACTED_A.pdf (298436465 B)
INFO:__main__:Uploading File:REDACTED_A.pdf
Sleeping for 9.9 seconds, 2023-08-16 08:22:32
Sleeping for 10.0 seconds, 2023-08-16 08:22:42
Sleeping for 9.9 seconds, 2023-08-16 08:22:52
Sleeping for 9.8 seconds, 2023-08-16 08:23:03
Sleeping for 10.0 seconds, 2023-08-16 08:23:12
INFO:__main__:PDF for REDACTED_B.pdf (303047029 B)
INFO:__main__:Uploading REDACTED_B.pdf
Sleeping for 9.9 seconds, 2023-08-16 08:30:34
Sleeping for 9.9 seconds, 2023-08-16 08:30:44
Sleeping for 9.9 seconds, 2023-08-16 08:30:54
Sleeping for 9.9 seconds, 2023-08-16 08:31:04
Sleeping for 9.7 seconds, 2023-08-16 08:31:14
ERROR: User assertion failed. Forcing re-login.
Logging in to commons:commons as REDACTED_ACCOUNT_NAME
WARNING: API warning (main): Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of A
PI deprecations and breaking changes. Use [[Special:ApiFeatureUsage]] to see usage of deprecated features by your application.
WARNING: API warning (login): Fetching a token via "action=login" is deprecated. Use "action=query&meta=tokens&type=login" instead.
ERROR: Received incorrect login token. Forcing re-login.
Sleeping for 9.1 seconds, 2023-08-16 08:31:25
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 08:31:34
...
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.8 seconds, 2023-08-16 09:26:54
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 09:27:04
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 09:27:14
...
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 10:21:04
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 10:21:14
WARNING: API error badtoken: Invalid CSRF token.
Sleeping for 9.9 seconds, 2023-08-16 10:21:24
...
```