PythonのSeleniumエラー

PythonSeleniumを使ってscrapingしているんだけど、

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot activate web view
selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: xxx.xxx

が出る。

stackoverflow.com

のサイトどおり、

    options.add_argument("--disable-infobars")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--disable-browser-side-navigation")
    options.add_argument("--disable-gpu")
    options.add_argument("--disable-features=VizDisplayCompositor")

を指定すると改善した。

pythonでmysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query')

pythonseleniumスクレイピングしたデータを Sqlalchemyを使って、mysqlにデータを登録しているが いくつかデータを登録したところで、エラーが発生して苦しんでいる。

mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query')

うーん。何が原因なんだろうか。。。

curlコマンドでレスポンスヘッダを表示する

curlコマンドでレスポンスヘッダを表示するには、以下の方法。

  • --dump-header(-D) オプションを指定する。
  • -I オプションを指定する(レスポンスヘッダのみ表示)

--dump-headerには出力先を指定が必要。 -とすれば 標準出力が出力先になる

curl --dump-header - http://www.w3c.org/

Twitter APIで"Client Forbidden"エラー

Tweeter APIを使用したアプリを作成していて、以下のエラーではまった。

When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.

Twitter Developer Potalで表示されるBearer Tokenをつけたcurlコマンドを実行しているのだが、何故かエラーが出る。 Bearer Tokenは、Developer Potalで出力したものを設定しているのに。。。

curl "https://api.twitter.com/2/tweets?ids=1261326399320715264,1278347468690915330" -H "Authorization: Bearer $BearerToken"

あれこれ、ハマった結果、Developer Potalでアプリはあるけど、プロジェクトが紐付けられてなかった。 プロジェクトを作成したら、エラーにならなくなりました。。。

よくみたらエラーメッセージの中に書いてるやん。。。英語を鍛えないとなぁ。

you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.