From 617c30a8c34c1d22bba974a76ae9a22032deb397 Mon Sep 17 00:00:00 2001 From: halcy Date: Thu, 24 Nov 2022 22:02:50 +0200 Subject: Remove mastosoc default instance --- mastodon/Mastodon.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index f0d9cc5..e7ec143 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -167,7 +167,6 @@ class Mastodon: If anything is unclear, check the official API docs at https://github.com/mastodon/documentation/blob/master/content/en/client/intro.md """ - __DEFAULT_BASE_URL = 'https://mastodon.social' __DEFAULT_TIMEOUT = 300 __DEFAULT_STREAM_TIMEOUT = 300 __DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5 @@ -260,17 +259,17 @@ class Mastodon: ### @staticmethod def create_app(client_name, scopes=__DEFAULT_SCOPES, redirect_uris=None, website=None, to_file=None, - api_base_url=__DEFAULT_BASE_URL, request_timeout=__DEFAULT_TIMEOUT, session=None): + api_base_url=None, request_timeout=__DEFAULT_TIMEOUT, session=None): """ Create a new app with given `client_name` and `scopes` (The basic scopes are "read", "write", "follow" and "push" - - more granular scopes are available, please refer to Mastodon documentation for which). - + - more granular scopes are available, please refer to Mastodon documentation for which) on the instance given + by `api_base_url`. + Specify `redirect_uris` if you want users to be redirected to a certain page after authenticating in an OAuth flow. You can specify multiple URLs by passing a list. Note that if you wish to use OAuth authentication with redirects, the redirect URI must be one of the URLs specified here. Specify `to_file` to persist your app's info to a file so you can use it in the constructor. - Specify `api_base_url` if you want to register an app on an instance different from the flagship one. Specify `website` to give a website for your app. Specify `session` with a requests.Session for it to be used instead of the default. This can be @@ -282,6 +281,8 @@ class Mastodon: Returns `client_id` and `client_secret`, both as strings. """ + if api_base_url is None: + raise MastodonIllegalArgumentError("API base URL is required.") api_base_url = Mastodon.__protocolize(api_base_url) request_data = { @@ -299,12 +300,10 @@ class Mastodon: if website is not None: request_data['website'] = website if session: - ret = session.post(api_base_url + '/api/v1/apps', - data=request_data, timeout=request_timeout) + ret = session.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout) response = ret.json() else: - response = requests.post( - api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout) + response = requests.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout) response = response.json() except Exception as e: raise MastodonNetworkError("Could not complete request: %s" % e) @@ -327,11 +326,11 @@ class Mastodon: request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None, version_check_mode="created", session=None, feature_set="mainline", user_agent="mastodonpy"): """ - Create a new API wrapper instance based on the given `client_secret` and `client_id`. If you - give a `client_id` and it is not a file, you must also give a secret. If you specify an - `access_token` then you don't need to specify a `client_id`. It is allowed to specify - neither - in this case, you will be restricted to only using endpoints that do not - require authentication. If a file is given as `client_id`, client ID, secret and + Create a new API wrapper instance based on the given `client_secret` and `client_id` on the + instance given by `api_base_url`. If you give a `client_id` and it is not a file, you must + also give a secret. If you specify an `access_token` then you don't need to specify a `client_id`. + It is allowed to specify neither - in this case, you will be restricted to only using endpoints + that do not require authentication. If a file is given as `client_id`, client ID, secret and base url are read from that file. You can also specify an `access_token`, directly or as a file (as written by `log_in()`_). If @@ -347,10 +346,6 @@ class Mastodon: even in "wait" and "pace" mode, requests can still fail due to network or other problems! Also note that "pace" and "wait" are NOT thread safe. - Specify `api_base_url` if you wish to talk to an instance other than the flagship one. When - reading from client id or access token files as written by Mastodon.py 1.5.0 or larger, - this can be omitted. - By default, a timeout of 300 seconds is used for all requests. If you wish to change this, pass the desired timeout (in seconds) as `request_timeout`. @@ -378,9 +373,9 @@ class Mastodon: If no other `User-Agent` is specified, "mastodonpy" will be used. """ - self.api_base_url = None - if api_base_url is not None: - self.api_base_url = Mastodon.__protocolize(api_base_url) + if api_base_url is None: + raise MastodonIllegalArgumentError("API base URL is required.") + self.api_base_url = Mastodon.__protocolize(api_base_url) self.client_id = client_id self.client_secret = client_secret -- cgit v1.2.3