Archive for the ‘python’ Category

Printing the generated query including parameters

January 16, 2020 Leave a comment

Categories: Interesting, python Tags: ,

Getting Started with Heroku – notes

January 6, 2020 Leave a comment


1. Install the heroku cli.
2. If you have a preexisting git repository with the desired files to be pushed to heroku.
You need to have at minimum a Procfile and requirements.txt file

$ less Procfile
web: gunicorn wsgi:app
$ less requirements.txt

3. Merge changes into master branch if working off a different branch.
4. Login into heroku.
$ heroku login
5. Create a heroku app. You can specify a name for the app. Below command generate a random name.
$ heroku create
To create an app outside the default region of the us.
$ heroku create midnight-cask-76349 --region eu
6. Create a heroku postgres database.
$ heroku addons:create heroku-postgresql:hobby-dev
7. Push changes up to heroku app. Alembic changes get applied automatically on successful deploy.
$ git push heroku master
8. Set application `Config vars` under settings on the dashboard
9. Get database application details from dashboard. Follow link from database details under installed addons section. THe database url details will be available under the linked settings. Also have instructions on how to connect to database
$ heroku pg:psql postgresql-sparkle-97339 --app midnight-cask-76349
10. To manually run alembic
$ heroku run alembic upgrade head
11. To check logs
$ heroku logs --tail
12. To get database credentials
$ heroku pg:credentials:url
13. You can clone the heroku repo for the app locally
$ heroku git:clone -a midnight-cask-76349


Categories: postgresql, python Tags:

SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)

November 30, 2019 Leave a comment

I was not able to run $ python3.7 -m pip install --upgrade pip on my Ubuntu 14.0 (Trusty) box. I was getting an error similar to

Could not fetch URL There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’’, port=443): Max retries exceeded with url: /simple/slackclient/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) – skipping

I had to manually install openssl and python3.7 for it to work on Ubuntu Trusty.


Categories: python Tags:

Improve your tests in Django with fakes and factories

August 12, 2019 Leave a comment

In our Django apps, we have the M(odel)T(emplate)V(iew) structure (mostly known as MVC). When we want to test its functionality we usually have to create some model instances and work with them and the database.

A nice and easy approach for doing so is to create fake data in our tests in the form of factories and fakers.

In the following article, we are going to look at some practical examples and techniques. This will improve the readability and behavior of your tests.


Categories: python Tags: ,

OSError: [Errno 8] Exec format error

June 5, 2019 Leave a comment

$ python3
* Serving Flask app "petsrus.petsrus" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "", line 4, in"", port=5000)
File "/home/vagrant/env/lib/python3.4/site-packages/flask/", line 944, in run
run_simple(host, port, self, **options)
File "/home/vagrant/env/lib/python3.4/site-packages/werkzeug/", line 1007, in run_simple
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
File "/home/vagrant/env/lib/python3.4/site-packages/werkzeug/", line 332, in run_with_reloader
File "/home/vagrant/env/lib/python3.4/site-packages/werkzeug/", line 176, in restart_with_reloader
exit_code =, env=new_environ, close_fds=False)
File "/usr/lib/python3.4/", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.4/", line 859, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.4/", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error


Added #!/usr/bin/env python to the file

#!/usr/bin/env python
from myapp import app

if __name__ == "__main__":"", port=5000)


Categories: python

Vim as a Python IDE

February 1, 2019 Leave a comment

VIM as a Python IDE

This project aims to use Vim as a powerful and complete Python IDE. In order to do that, we curated a list of awesome plugins available in the community and provided an automatic installation procedure for this set.


Categories: Interesting, python, vim Tags:

Designing Well-Structured REST APIs with Flask-RestPlus: Part 1

December 11, 2018 Leave a comment

This is the first part of a two-part series. In this post, I will introduce Flask-RestPlus and demonstrate how to start organising APIs around its simple REST-based conventions. Next time, I will address the topic of request/response marshalling (serialisation) and validation.

Categories: python Tags: