diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index fc585ba..37e35b7 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -2214,9 +2214,12 @@ class Mastodon:
             if not response_object.ok:
                 try:
                     response = response_object.json(object_hook=self.__json_hooks)
-                    if not isinstance(response, dict) or 'error' not in response:
+                    if isinstance(response, dict) and 'error' in response:
+                        error_msg = response['error']
+                    elif isinstance(response, str):
+                        error_msg = response
+                    else:
                         error_msg = None
-                    error_msg = response['error']
                 except ValueError:
                     error_msg = None
 

"string indices must be integers" when handling an error

```
TypeError('string indices must be integers',)

Traceback (most recent call last):
...
  File "/home/codl/forget/libforget/mastodon.py", line 165, in refresh_posts
    status = api.status(post.mastodon_id)
  File "</home/codl/.local/share/virtualenvs/forget-jXTy0Bc2/lib/python3.6/site-packages/decorator.py:decorator-gen-10>", line 2, in status
  File "/home/codl/.local/share/virtualenvs/forget-jXTy0Bc2/lib/python3.6/site-packages/mastodon/Mastodon.py", line 77, in wrapper
    return function(self, *args, **kwargs)
  File "/home/codl/.local/share/virtualenvs/forget-jXTy0Bc2/lib/python3.6/site-packages/mastodon/Mastodon.py", line 620, in status
    return self.__api_request('GET', url)
  File "/home/codl/.local/share/virtualenvs/forget-jXTy0Bc2/lib/python3.6/site-packages/mastodon/Mastodon.py", line 2202, in __api_request
    error_msg = response['error']
```

this is the code in question ↓

https://github.com/halcy/Mastodon.py/blob/55ec333562d49ac8ac65000e0c01ae88255576f1/mastodon/Mastodon.py#L2197-L2204

i think i wrote this, haha

my best guess for how this could happen is if the error page returns a bare json string with the word "error" in it. i think this was on a pleroma instance but i couldnt look into it further at the time
diff --git a/tests/test_errors.py b/tests/test_errors.py
new file mode 100644
index 0000000..7329507
--- /dev/null
+++ b/tests/test_errors.py
@@ -0,0 +1,20 @@
+import pytest
+from mastodon.Mastodon import MastodonAPIError
+
+try:
+    from mock import MagicMock
+except ImportError:
+    from unittest.mock import MagicMock
+
+def test_nonstandard_errors(api):
+    response = MagicMock()
+    response.json = MagicMock(return_value=
+            "I am a non-standard instance and this error is a plain string.")
+    response.ok = False
+    session = MagicMock()
+    session.request = MagicMock(return_value=response)
+
+    api.session = session
+    with pytest.raises(MastodonAPIError):
+        api.instance()
+

pip install -e .[test]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-vcr pytest-mock
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
coverage==7.8.0
cryptography==44.0.2
decorator==5.2.1
exceptiongroup==1.2.2
http_ece==1.2.1
idna==3.10
iniconfig==2.1.0
-e git+https://github.com/halcy/Mastodon.py.git@8b8626978752baf14347498640b2319db832145e#egg=Mastodon.py
multidict==6.2.0
packaging==24.2
pluggy==1.5.0
propcache==0.3.1
pycparser==2.22
pytest==8.3.5
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-runner==6.0.1
pytest-vcr==1.0.2
python-dateutil==2.9.0.post0
python-magic==0.4.27
pytz==2025.2
PyYAML==6.0.2
requests==2.32.3
six==1.17.0
tomli==2.2.1
typing_extensions==4.13.0
urllib3==1.26.20
vcrpy==7.0.0
wrapt==1.17.2
yarl==1.18.3

name: Mastodon.py
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - cffi==1.17.1
      - charset-normalizer==3.4.1
      - coverage==7.8.0
      - cryptography==44.0.2
      - decorator==5.2.1
      - exceptiongroup==1.2.2
      - http-ece==1.2.1
      - idna==3.10
      - iniconfig==2.1.0
      - multidict==6.2.0
      - packaging==24.2
      - pluggy==1.5.0
      - propcache==0.3.1
      - pycparser==2.22
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - pytest-mock==3.14.0
      - pytest-runner==6.0.1
      - pytest-vcr==1.0.2
      - python-dateutil==2.9.0.post0
      - python-magic==0.4.27
      - pytz==2025.2
      - pyyaml==6.0.2
      - requests==2.32.3
      - six==1.17.0
      - tomli==2.2.1
      - typing-extensions==4.13.0
      - urllib3==1.26.20
      - vcrpy==7.0.0
      - wrapt==1.17.2
      - yarl==1.18.3
prefix: /opt/conda/envs/Mastodon.py

tests/test_errors.py::test_nonstandard_errors
mastodon/Mastodon.py
mastodon/Mastodon.py