heroku / heroku.py Goto Github PK
View Code? Open in Web Editor NEWThis project has been sunset. See: https://github.com/heroku/heroku.py/issues/61
Home Page: https://pypi.org/project/heroku/
License: MIT License
This project has been sunset. See: https://github.com/heroku/heroku.py/issues/61
Home Page: https://pypi.org/project/heroku/
License: MIT License
If you've got an application, and it currently has no addons, eg:
>>> app.addons
[]
You're unable to add any new addons until at least one exists:
>>> new_addon = app.addons.add('heroku-postgresql:dev')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rdegges/.virtualenvs/postgresly/local/lib/python2.7/site-packages/heroku/structures.py", line 50, in add
return o.new(*args, **kwargs)
File "/home/rdegges/.virtualenvs/postgresly/local/lib/python2.7/site-packages/heroku/models.py", line 126, in new
resource=('apps', self.app.name, 'addons', name)
AttributeError: 'Addon' object has no attribute 'app'
So, the workaround (currently) is to add an addon manually using some other method (eg: the CLI tool), and then everything works as expected.
#14 made it possible to scale processes from 0 to any quantity, but #29 removed this feature. Currently, we can do this by the following hack (assuming there is no worker process running for myapp):
import heroku
from heroku.models import Process
h = heroku.from_key(...)
app = h.apps['myapp']
Process.new_from_dict({'process': 'worker'}, h, app=app).scale(10)
But it would be best to be supported officially.
There are two cases that could probably be patched and prevented:
The Heroku Toolbelt prevents these from happening, so I'm guessing you guys like to prevent this behaviour :) However, both of these calls currently throw a KeyError:
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/structures.py", line 55, in add
return self[0].new(*args, **kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/models.py", line 515, in new
return self.app.processes[type]
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/structures.py", line 106, in __getitem__
raise why
KeyError: 'web'
Now we could add code inside Process.scale() and Process.new() to check for non-integers and quantities < 1. However it seems like The Heroku Way in this module is to try taking actions and raise errors if they don't work? Also on the HEAD branch if we try to scale a process to a number of dynos that's < 1 we get this response from the server:
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/structures.py", line 46, in add
return self[0].new(_args, *_kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/models.py", line 505, in new
data={'type': type, 'qty': quantity}
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/api.py", line 103,in _http_resource
raise http_error
requests.exceptions.HTTPError: 422 Client Error: {"error":"Cannot scale to fewer than 0 dynos per process type."}
So perhaps you'd prefer to write server code to deal with these situations instead, which will then get caught by the calls to r.raise_for_status() in both Process.new() and Process.scale()
Let me know! :)
The readme says:
cloud = Heroku(session=session)
When I try this, I get:
Traceback (most recent call last):
File "./merge", line 18, in <module>
cloud = Heroku(session=session)
TypeError: __init__() got an unexpected keyword argument 'session'
with the following requirements.txt:
requests==0.14.2
git+git://github.com/heroku/heroku.py.git
(note had to peg requests
to get r = requests.get(r.content, verify=False, prefetch=False)
to work)
and the following snipit:
for line in self.app.logs(tail=True):
print line
the script will print about 100 lines, then hang.
Any ideas on what I am doing wrong?
Thanks!
Say I have a pretty standard procfile declaring a "web" and a "worker" process. The default state for my app is to have a single web dyno running, and no workers running, using heroku.py to file up workers on demand.
However, when 0 workers are running,
app.processes['worker'].scale(0)
causes KeyError. In other words the process map only contains information about currently running dynos regardless of the contents of the procfile, making it impossible to automate the transition from 0 to 1 workers.
Because of API changes from requests 0.14.2 to 1.0.0, this project currently requires requests < 1.0. This may be a trap for people installing heroku.py via pip. An upgrade to requests 1.1.0 would be much appreciated ;-)
This is due to the following code at the end of Process.scale()
:
if self.type in self.app.processes:
return self.app.processes[self.type]
else:
return ProcessListResource()
Here the test always fails because __contains__
is not defined for ProcessListResource
and every Process
is different from self.type
because there is no __eq__
in Process
.
The correct implementation would be using try-except block:
try:
return self.app.processes[self.type]
except KeyError:
return ProcessListResource()
Hey,
Can you add a Process example to the readme? I believe that class is used for doing one off executions. If that's not what its for, what is the equivalent of a heroku run with this wrapper?
This project has been deprecated for some time, and is now being sunset since the published version currently doesn't work with Python 3 or newer versions of requests.
We recommend that you use the maintained https://github.com/martyzz1/heroku3.py instead.
If you really need to continue to use this library, you will need to specify an explicit version in your pip requirements file (such as heroku==0.1.4
) or else use the GitHub repository version (using a requirement specifier of git+https://github.com/heroku/heroku.py.git
).
Apps (and potentially also the user) should support the labs
commands, see https://github.com/heroku/heroku/blob/master/lib/heroku/command/labs.rb
Heroku is such a nice platform and having a Python wrapper around its API just makes it more awesome...
There doesn't seem to be any way to access the slug ID:
https://devcenter.heroku.com/articles/platform-api-copying-slugs
I'm trying to automate some of our app management overhead by writing scripts that utilize heroku's Rest API via Python. The package I'm referring to can be found at:
http://pypi.python.org/pypi/heroku/0.1.2
The first part of the tutorial works, whether using password or API key:
import heroku
cloud = heroku.from_pass('[email protected]', 'xxxxxxx')`
or
cloud = heroku.from_key('YOUR_API_KEY')
However, when I run
cloud.apps
I get an empty list []
I submitted this issue to Heroku and they said to create a GitHub issue.
It would be very nice to be able to run commands on heroku apps from the Python API.
gabriel@delta:~$ heroku login
Enter your Heroku credentials.
Email: [email protected]
Password (typing will be hidden):
Authentication successful.
~/.netrc file is updated per usual.
>>> h=heroku.from_key('key-for-user2')
>>> h.keys
[<key '[email protected]'>]
D'oh it's using a session from user1 via .netrc even though we provided user2's key.
Worst part is it doesn't warn you. It just silently proceeds as the wrong user.
Does this library officially support Python 3?
If so, it would be nice to designate that on PyPI using classifiers in setup.py (I see that 3.0 and 3.1 are commented out in github, and PyPI lists 3.1 and 3.2, which is confusing...).
If not, what does the path forward look like?
cloud.apps do not work because the url https://api.heroku.com/apps is deprecated since yesterday. Instead show the exception: "requests.exceptions.HTTPError: 410 Client Error: Gone for url: https://api.heroku.com/apps"
Is possible to have a resolution for this issue?
Possible reason of the issue occurrence:
https://devcenter.heroku.com/changelog-items/1147
“Legacy Platform API Brownouts start May 24th
(...) final shutdown Monday, June 26th.
Please see our original deprecation announcement for further details and our status site for upcoming brownout dates and times.”
Hi,
I'm currently trying to scale back to 0 workers after im finished with my task. As the task is run maybe only several times a month.
So what I'm trying to do is the following:
I did some testing in the django shell but noticed that even there it is not working how i want it to work.
It always returns an key error as soon as the worker is scaled down, as you can see it even returns an key error as result when i call scale(0) on the worker process. Am I using the api in the wrong way?
See below shell log:
In [38]: app.processes['celeryd'].scale(1)
Out[38]: [<process 'celeryd.1'>]
In [39]: app.processes['celeryd'].scale(0)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/<ipython-input-39-6ae980b2874f> in <module>()
----> 1 app.processes['celeryd'].scale(0)
heroku/structures.pyc in scale(self, quantity)
93
94 def scale(self, quantity):
---> 95 return self[0].scale(quantity)
96
97
eroku/models.pyc in scale(self, quantity)
541 r.raise_for_status()
542
--> 543 return self.app.processes[self.type]
544
545
thon2.7/site-packages/heroku/structures.pyc in __getitem__(self, key)
82 return ProcessTypeListResource(items=c)
83 else:
---> 84 raise why
85
86
KeyError: u'celeryd'
In [40]: app.processes['celeryd'].scale(1)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
python-input-40-5c5022e042ff> in <module>()
----> 1 app.processes['celeryd'].scale(1)
.7/site-packages/heroku/structures.pyc in __getitem__(self, key)
82 return ProcessTypeListResource(items=c)
83 else:
---> 84 raise why
85
86
KeyError: 'celeryd'
There should be a way to specify the buildpack to use when a new app is created.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.