File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,24 @@ class AuthenticationError(Exception):
2323 pass
2424
2525
26+ class NoTokenError (Exception ):
27+ pass
28+
29+
2630def get_api_endpoint ():
2731 domain = os .environ .get ('PYTHONANYWHERE_DOMAIN' , 'pythonanywhere.com' )
2832 return 'https://www.{domain}/api/v0/user/{{username}}/webapps/' .format (domain = domain )
2933
3034
3135def call_api (url , method , ** kwargs ):
32- token = os .environ ['API_TOKEN' ]
36+ token = os .environ .get ('API_TOKEN' )
37+ if token is None :
38+ raise NoTokenError (
39+ "Oops, you don't seem to have an API token. "
40+ "Please go to the 'Account' page on PythonAnywhere, then to the 'API Token' "
41+ "tab. Click the 'Create a new API token' button to create the token, then "
42+ "start a new console and try running this script again."
43+ )
3344 insecure = os .environ .get ('PYTHONANYWHERE_INSECURE_API' ) == 'true'
3445 response = requests .request (
3546 method = method ,
You can’t perform that action at this time.
0 commit comments