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.