9/19/17

Installing Selenium and ChromeDriver on Ubuntu 16.04

Install xvfb:

sudo apt-get install xvfb

Install Google Chrome:

sudo apt install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt install -f

Install ChromeDriver:


wget -N https://chromedriver.storage.googleapis.com/2.34/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
Install Selenium:


sudo apt-get install python-pip
pip install pyvirtualdisplay selenium

Example:

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Chrome()
driver.get('http://blog.python.org.ua')
print driver.title

MacOS SSLV3_ALERT_HANDSHAKE_FAILURE

Error:
(Caused by SSLError(SSLError(1, u'[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:661)'),))

Solution:
brew install openssl
pip install cryptography

9/15/17

Deploy aiohttp with gunicorn and nginx

sudo apt-get install python3 virtualenv supervisor

cd /home/user/aiohttp
virtualenv env --no-site-packages -p python3

source env/bin/activate

pip install aiohttp
pip install

nano gunicorn.conf.py

bind = "127.0.0.1:8081"
workers = 2
worker_class = "aiohttp.worker.GunicornWebWorker"

nano /etc/supervisor/conf.d/apptest.conf

[program:apptest]
command=/home/user/aiohttp/env/bin/gunicorn app_test:my_web_app -c /home/user/aiohttp/gunicorn.conf.py
directory=/home/user/aiohttp
user=nobody
autostart=true
autorestart=true

nano /etc/nginx/conf.d/apptest.conf

upstream apptest_server {
    server unix:/tmp/apptest.sock fail_timeout=0;
}

server {
    listen       80;
    server_name  192.168.1.10;

    root /home/user/aiohttp/static;

    location / {
      try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://127.0.0.1:8081;
    }
}

service supervisor restart
service nginx restart