Open GamePlayer-8 opened 3 months ago
Sigh. I genuinely wish people would stop making up new creative ways of formatting the version string for the API and just put the version of the API that their server software tries to support in there, or use any of the things people already do. I already have like 3 different weird edge cases for pleroma and masto forks, apparently sharkey invented yet another way that I get to put in now ("version": "3.0.0 (compatible; Sharkey 2024.3.1)")
anyways: set "version_check_mode" to "none" (string "none", lowercase) in the constructor, that should hopefully mostly work. Some functions that disambiguate by version may not work (mostly search), use the _v1 or _v2 variants of those explicitly.
thank you! ❤️
Also for reporting streaming API errors should I refer to the Sharkey devs or here (in the issue tracker)? I.e.:
Traceback (most recent call last):
File "/source/runner.py", line 219, in <module>
setup()
File "/source/runner.py", line 216, in setup
main()
File "/source/runner.py", line 195, in main
stream = mastodon_instance.stream_user(listener, run_async=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/utility.py", line 49, in wrapper
return function(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/streaming_endpoints.py", line 21, in stream_user
return self.__stream('/api/v1/streaming/user', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/internals.py", line 429, in __stream
url = self.__get_streaming_base()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/internals.py", line 403, in __get_streaming_base
instance = self.instance()
^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/utility.py", line 49, in wrapper
return function(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/instance.py", line 24, in instance
return self.__instance()
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/instance.py", line 30, in __instance
instance = self.__api_request('GET', '/api/v1/instance/')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/internals.py", line 297, in __api_request
raise ex_type('Mastodon API returned error', response_object.status_code, response_object.reason, error_msg)
mastodon.errors.MastodonNotFoundError: ('Mastodon API returned error', 404, 'Not Found', {'message': 'Unknown API endpoint.', 'code': 'UNKNOWN_API_ENDPOINT', 'id': '2ca3b769-540a-4f08-9dd5-b5a825b6d0f1', 'kind': 'client'})
Ah, hm. Maybe Sharkey implements only the v2 version of the instance API, not the v1. Since Mastodon does not remove the old ones, I currently do not take that into account. I should probably do that.
Both would be good, probably, ideally they should support v1 for compat, and I should obviously use v2 when v1 is not available.
Currently once again busy with other stuff, so I can't promise a timeline on a fix, but if you want to quickly kludge it yourself, you probably can make it work by looking at api docs and swapping URLs around (maybe even just v1 to v2 in there is good enough, not sure)
Thank you, in any case, for the report!
Currently once again busy with other stuff, so I can't promise a timeline on a fix, but if you want to quickly kludge it yourself, you probably can make it work by looking at api docs and swapping URLs around (maybe even just v1 to v2 in there is good enough, not sure)
Is that possible to specify which version API (v1
or v2
) can be used by Mastodon.py or do I need to proxy /api/v1
directive to /api/v2
at the server side?
it's per endpoint, there's (intended to be a) _v1 and _v2 version for functions that have multiple variants and one without suffix that selects dynamically, but I think in the current stable version on pip, I didn't implement that for the v2 instance API yet (and in any case, the reason it fails for streaming is that the streaming API calls this internally because I needs to get the streaming endpoints from the return value, so you actually couldn't fix it that way). I will, eventually, but I keep getting sidetracked. As a workaround, you could edit your local copy of Mastodon.py and replace /v1/ with /v2/ in the "__instance" function (may break things) or, as you said, proxy rewrite it.
unfortunately v1
seems to have differ from v2
a bit more:
Traceback (most recent call last):
File "/home/gameplayer/workspace/followatch-sharkey/app/runner.py", line 223, in <module>
setup()
File "/home/gameplayer/workspace/followatch-sharkey/app/runner.py", line 214, in setup
main()
File "/home/gameplayer/workspace/followatch-sharkey/app/runner.py", line 187, in main
mastodon_instance.status_post('**FolloWatch** Booted up.', visibility='direct')
File "/usr/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/utility.py", line 49, in wrapper
return function(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/statuses.py", line 248, in status_post
return self.__status_internal(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/statuses.py", line 182, in __status_internal
return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mastodon/internals.py", line 297, in __api_request
raise ex_type('Mastodon API returned error', response_object.status_code, response_object.reason, error_msg)
mastodon.errors.MastodonNotFoundError: ('Mastodon API returned error', 404, 'Not Found', 'Not Found')
As a workaround, you could edit your local copy of Mastodon.py and replace /v1/ with /v2/ in the "__instance" function
Will try that now.
('Mastodon API returned error', 404, 'Not Found', AttribAccessDict([('message', 'Unknown API endpoint.'), ('code', 'UNKNOWN_API_ENDPOINT'), ('id', '2ca3b769-540a-4f08-9dd5-b5a825b6d0f1'), ('kind', 'client')]))
Traceback (most recent call last):
File "/home/gameplayer/workspace/followatch-sharkey/app/runner.py", line 224, in <module>
setup()
File "/home/gameplayer/workspace/followatch-sharkey/app/runner.py", line 215, in setup
main()
File "/home/gameplayer/workspace/followatch-sharkey/app/runner.py", line 194, in main
stream = mastodon_instance.stream_user(listener, run_async=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gameplayer/workspace/followatch-sharkey/app/mastodon/versions.py", line 43, in wrapper
return function(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gameplayer/workspace/followatch-sharkey/app/mastodon/streaming_endpoints.py", line 21, in stream_user
return self.__stream('/api/v2/streaming/user', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gameplayer/workspace/followatch-sharkey/app/mastodon/internals.py", line 370, in __stream
url = self.__get_streaming_base()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gameplayer/workspace/followatch-sharkey/app/mastodon/internals.py", line 343, in __get_streaming_base
instance = self.__instance()
^^^^^^^^^^^^^^^^^
File "/home/gameplayer/workspace/followatch-sharkey/app/mastodon/instance.py", line 35, in __instance
instance = self.__api_request('GET', '/api/v2/instance/', override_type=Instance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gameplayer/workspace/followatch-sharkey/app/mastodon/internals.py", line 252, in __api_request
raise ex_type('Mastodon API returned error', response_object.status_code, response_object.reason, error_msg)
mastodon.errors.MastodonNotFoundError: ('Mastodon API returned error', 404, 'Not Found', AttribAccessDict([('message', 'Unknown API endpoint.'), ('code', 'UNKNOWN_API_ENDPOINT'), ('id', '2ca3b769-540a-4f08-9dd5-b5a825b6d0f1'), ('kind', 'client')]))
replacing v1
with v2
in the source code causes 404 error. Will probably forward the issue as well to the Sharkey devs.
Good afternoon,
How do I disable the check of remote Mastodon instance version in Mastodon.py?
I'm using Sharkey version
v2024.3.1
which contains an API mostly compatible with Mastodon API.The current error what I'm getting is: