# 現状

centos7(VPS)+nginx+uwsgi+flask+seleniumでブラウザーから渡されたURLでスクリーンショットを取ろうとしているのですが、chromedriver（chrome本体?）が起動に失敗します。

## 確認したこと

  * nginxを経由せずにflaskの単体サーバーでは問題ありませんでした。
  * uwsgi経由でflaskサーバー立ち上げて実行しても問題ありませんでした。
  * 画面がありませんので、Xvfbを使用してます。
  * nginxはhttpsになります。

どうもlocalhostの名前解決ができていないような感じがあるのですが。  
解決策ご存じの方よろしくお願いいたします。

## エラー

```

    Traceback (most recent call last):
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
      File "./api/route_api_walls.py", line 56, in create_walls_data
    selenium_util = libs.SeleniumUtility(request_form_dict['url'])
      File "./libs/seleniumutility.py", line 35, in __init__
    self.driver = webdriver.Chrome(chrome_options=opts,executable_path=self.driver_location,service_log_path=self.service_log_path)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 86, in __init__
    desired_capabilities=desired_capabilities)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 155, in __init__
    self.start_session(desired_capabilities, browser_profile)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 244, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
    self.error_handler.check_response(response)
      File "/usr/local/pyenv/versions/3.6.1/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 246, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
      (Driver info: chromedriver=2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752),platform=Linux 3.10.0-693.17.1.el7.x86_64 x86_64)
    
```

## uwsgiの設定

```

    [uwsgi]
    uid =nginx
    gid = nginx
    chdir = /var/www/xxxxx/xxxxxx
    app = index:app
    module = %(app)
    callable = app
    logto = /var/log/uwsgi/%n.log
    master = true
    processes = 5
    socket = xxxxxx.sock
    chmod-socket =666
    vacuum = true
    die-on-term = true
    
```

## nginxの設定

```

    location / {
        include uwsgi_params;
        uwsgi_read_timeout 3000;
        uwsgi_pass unix:/var/www/xxxxx/xxxxxx/xxxxxx.sock;
    }
    
```

## ソースコード(一部)

```

    def __init__(self, url):
            self.display = Display(visible=0, size=(1366, 768))
            self.display.start()
    
            opts = Options()
            opts.binary_location = self.browser_path
            opts.add_argument('--headless')
            opts.add_argument('--disable-gpu')
            opts.add_argument('--no-sandbox')
            self.driver = webdriver.Chrome(chrome_options=opts,executable_path=self.driver_location,service_log_path=self.service_log_path)
            self.driver.get(url)
    
```

### 補足

<https://teratail.com/questions/121424>  
とのマルチポストになります。  
解決策は相互に記述しますので、ご容赦ください。
CC BY-SA 3.0
2018-04-13T01:38:08.837
43191
2018-04-13T03:04:23.257
2018-04-13T03:04:23.257
28139
28139
question
python nginx selenium flask selenium-webdriver
centos7+nginx+uwsgi+flask+seleniumでchromedriverが立ち上がらない。