我正在弄清楚如何在谷歌云平台上部署我的脚本。
我已经创建了一个包含以下内容的目录或文件夹script.py
以及所有的图书馆/lib
文件夹。
我不明白的是设置我的app.yaml
to run script.py
(python 2.7)和访问lib
如果需要的话。
我也不知道是否需要做requirments.txt
因为我使用第三方库。
这是我所有的进口商品script.py
import requests
import re
import mysql.connector
from urlparse import urlparse
from urlparse import urljoin
from bs4 import BeautifulSoup
另外,我的lib
是 BeautifulSoup、requests 和 mysql.connector。
我不知道其他的,我假设它们是内置的 python2.7,因为我无法使用 pip 安装它们。
顺便说一句,我使用的是 Windows 10。
app.yaml
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /lib/requests
script: Scrape.app
handlers:
- url: /requests
script: Scrape.app
handlers:
- url: /mysql/connector
script: Scrape.app
handlers:
- url: /bs4/
script: Scrape.app
cron.yaml
cron:
- description: "Scrape"
url: /
schedule: every 10 mins
retry_parameters:
min_backoff_seconds: 2.5
max_doublings: 10
我收到类似错误
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
/bin/sh: 1: Python: not found
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~tribal-bonito-157700/20170302t182530.399552845921654287/Scrape.py", line 3, in <module>
import requests
ImportError: No module named requests