Q&A
前提
GCPのCloud Functionに初めてトライするにあたり、
下記のWebページ通りに設定を進めていたところ、
デプロイ(webページ上の<4. デプロイ完了後、Cloud Functionsの画面に以下のように表示されます。>のところ)まではできたのですが
関数を実行するとエラーになります。
参考にしたサイト:Cloud SchedulerとCloud Functionsを使って自動スクレイピングさせて、スプレッドシートに書き出してみた(Python)
https://marketingengineercareer.com/cloudscheduler_cloudfunctions_python
実現したいこと
上記Webページ上の目次「5.3 Cloud Functions→6. wikipediaのどっかのページのタイトルが返ってきます。」までを実行させたいです。
発生している問題・エラーメッセージ
ターミナルで実行した場合のエラーメッセージ
Error: could not handle the request
テスト中タブでテストを実行した場合のエラーメッセージ
Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Details: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
該当のソースコード
import os from selenium import webdriver def handler(request): chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--window-size=1280x1696') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--hide-scrollbars') chrome_options.add_argument('--enable-logging') chrome_options.add_argument('--log-level=0') chrome_options.add_argument('--v=99') chrome_options.add_argument('--single-process') chrome_options.add_argument('--ignore-certificate-errors') chrome_options.binary_location = os.getcwd() + "/headless-chromium" driver = webdriver.Chrome(os.getcwd() + "/chromedriver",chrome_options=chrome_options) driver.get('https://en.wikipedia.org/wiki/Special:Random') line = driver.find_element_by_class_name('firstHeading').text print(line) driver.quit() return line
GCPのターミナル上に下記を入力して実行しています。(*****のところは自分の関数のURLを入れています)
curl https://asia-northeast1-************.cloudfunctions.net/handler
試したこと
・該当する関数のAuthenticationを「未認証を許可」に変更→エラーまま
・Cloud Functionの下記テストコマンドを実行→同じエラー
curl -m 70 -X POST https://asia-northeast1-************.cloudfunctions.net/handler \ -H "Authorization: bearer $(gcloud auth print-identity-token)" \ -H "Content-Type: application/json" \ -d '{}'