谷歌应用引擎上的Python 3 https请求不起作用

时间:2017-10-20 10:04:11

标签: python python-3.x google-app-engine nginx

我不熟悉为python部署app引擎的解决方案,并试图让一个简单的http请求工作但是徒劳无功。我正在使用试用版。 我已按照此操作使用vendoring指令安装请求和requests-toolbelt。 https://cloud.google.com/appengine/docs/standard/python/issue-requests

这是我的代码,以确保我做得对。当我使用谷歌云外壳部署解决方案时,它可以很好地构建,但是当查看部署的站点时,我只是收到错误 502 Bad Gateway nginx。 如果有任何帮助,可以在app引擎错误报告仪表板中找到错误

AttributeError:'NoneType'对象没有属性'add_extra_file'

  

load_wsgi   (/env/lib/python3.6/site-packages/gunicorn/workers/base.py:148)

追踪(最近一次呼叫最后一次):

  

文件“/home/vmagent/app/main.py”,第21行:   在import_app上的requests_toolbelt.adapters.appengine.monkeypatch()   (/env/lib/python3.6/site-packages/gunicorn/util.py:352)at at   load_wsgiapp   (/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py:52)在加载时   (/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py:65)在wsgi   (/env/lib/python3.6/site-packages/gunicorn/app/base.py:67)at at   load_wsgi   (/env/lib/python3.6/site-packages/gunicorn/workers/base.py:135)

我尝试了很多来自stackoverflow的解决方案,但无法找到解决方案。下面是代码。 main.js,app.yaml,requirements.txt

import logging
import requests
import requests_toolbelt.adapters.appengine
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    """Return a friendly HTTP greeting."""
        # Use the App Engine Requests adapter. This makes sure that Requests uses
        # URLFetch.
        requests_toolbelt.adapters.appengine.monkeypatch()
        url = 'http://www.google.com/humans.txt'
        response = requests.get(url)
        response.raise_for_status()
        #url = 'http://www.google.com/humans.txt'


    return response.text


@app.errorhandler(500)
def server_error(e):
    logging.exception('An error occurred during a request.')
    return """
    An internal error occurred: <pre>{}</pre>
    See logs for full stacktrace.
    """.format(e), 500


if __name__ == '__main__':
    # This is used when running locally. Gunicorn is used to run the
    # application on Google App Engine. See entrypoint in app.yaml.
    app.run(host='127.0.0.1', port=8080, debug=True)
  

requirements.txt Flask == 0.12.2 gunicorn == 19.7.1   应用。 YAML

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  python_version: 3

0 个答案:

没有答案