Forums

Pythonanywhere api for new console

Thanks for your GREAT Service. is there anyway to create a new console ( or run a custom console or even run a python script) with the API?

See the api documentation for how to create a console

thx

Thanks for detail but I'm new to Python and i wrote this but It doesn't work :(

import requests
import urllib
my_domain = 'xxx.pythonanywhere.com'
username = 'xxxx'
token = 'xxx'
params = urllib.parse.urlencode({'executable': 'python3.6', 'arguments': '-i /home/dopes/sweet.py', 
'working_directory': '/home/xxxx'})
response = requests.post('http://www.pythonanywhere.com/api/v0/user/{username}/consoles/'.format(username=username),params ,headers={'Authorization': 'Token {token}'.format(token=token)})

what do you expect to happen and what happens instead? is there an error stacktrace?

actually It doesn't work ( i mean it doesn't create a new console ) it just gives me List of all my consoles

>>> import requests
>>> import urllib
>>> params = urllib.parse.urlencode({'executable': 'python3.6', 'arguments': '-i /home/dopes/sweet.py', 
'working_directory': '/home/xxxx'})

>>> response = requests.post('http://www.pythonanywhere.com/api/v0/user/xxx/consoles/',params 
,headers={'Authorization': 'Token xxxxxxxxxxxxxxxx'})
>>> print(response)
<Response [200]>
>>> print(response.content)
b'[{"id":9180302,"user":"xxxx","executable":"python3.6","arguments":"-i 
/home/dopes/another.py","working_directory":"/home/xxxx","pid":2106,"name":"another.py 
(Python3.6)","console_url":"/user/xxx/consoles/9180302/","console_frame_url":"/user/xxxx/consoles/9180302/frame/"}]'
>>>

thanks.

As the docs say: That creates the console, but does not start it. We do not have an API endpoint for starting consoles at the moment.

I just wanted to add that without the ability to start a console via the API, the opportunities to use the API in any sort of automation are limited - you need to either resort to scheduled tasks only, or to having a pre-created console (whose ID at any time you might discover via the API).

thanks- we are aware of this problem with the console API. the API is in beta, and tweaking/expanding the API is definitely on our list of things to do.

Hello guys, is there any progress in terms of starting a new console from your API?

No, not at the moment.

Bumping this again as I've just come up against this limitation. I have a console I'm using via the API, but as soon as the servers reboot I can't access the console via the API until I manually open the console in browser. Really defeats the point of using the API for me! Would love to see something put into the API to solve this.

Thanks -- noted. Not sure what your use-case is, but maybe you could consider trying Scheduled tasks (or even Always-on tasks, but that'd require a paid account) or creating a web app (API) which would ease the workflow? Our consoles are not designed for long running jobs, anyway.

hi i am bumping this also, i want to run a task combined with zapier. in zapier i can use a python script any time an email arrives for example. but i cannot import certain things i need. using the api for this to execute a task would be great

What are the things that you can't import? Could you make a web app with the endpoint triggering an action that you need?

i cannot import gspread to zapier, (it works on here). i don't understand what you mean with "web app". my goal is to have a trigger from zapier (email in this example but it can be something more complex), to have an action on pythonanywhere. right now im checking everyday on pythoneverywhere if (in this example) an email is received to perform my action, with tasks. but i dont need to run my task continiously because i would get about 1 email per week. if the api would support me starting a script it would be great

Ok. Thanks for the suggestion.