我试图将python服务器放在Google Compute Engine上的VM中,其持续时间超过10分钟(服务的应用程序引擎中的时间限制)。我给你我的代码和输出:
from google.cloud import storage as gcs
from requests_toolbelt.adapters import appengine
appengine.monkeypatch()
def my_function(filename, stringdata):
# init client gcp
gcs_client = gcs.Client()
bucket = gcs_client.get_bucket(config["cloud_storage_segment"])
upload_blob_from_string(bucket, filename, stringdata)
输出告诉我:
文件“/home/guillermo.diaz/.local/lib/python2.7/site packages/flask/app.py”,第1994行,在call return self中。wsgi_应用程序(环境、启动_响应)
file"/home/user/. local/lib/python2.7/site-pack/flask/app.py",第1985行,wsgi_app响应=self.handle_exception(e)
文件“/home/user/.local/lib/python2.7/site packages/flask/app.py”,第1540行,在句柄异常重放中(exc类型,exc值,tb)
file"/home/user/. local/lib/python2.7/site-pack/flask/app.py",第1982行,wsgi_app响应=self.full_dispatch_request()
file"/home/user/. local/lib/python2.7/site-pack/flask/app.py",第1614行,full_dispatch_requestrv=self.handle_user_exception(e)
文件“/home/user/.local/lib/python2.7/site packages/flask/app.py”,第1517行,在handle\u user\u异常重放中(exc\u类型,exc\u值,tb)
文件“/home/user/.local/lib/python2.7/site packages/flask/app.py”,第1612行,完整发送请求rv=self。调度请求()
文件“/home/user/.local/lib/python2.7/site packages/flask/app.py”,第1598行,发送请求返回self。查看功能规则。endpoint
文件“/home/user/my_module/main.py”,第50行,在my_函数bucket=gcs_客户端中。获取存储桶(配置[“云存储段”])
file"/home/user/. local/lib/python2.7/site-包/谷歌/云/存储/client.py",第225行,get_bucketbucket.reload(客户端=自我)
file"/home/user/. local/lib/python2.7/site-包/谷歌/云/存储/_helpers.py",第108行,在重新加载_target_object=自我)
file"/home/user/. local/lib/python2.7/site-包/google/Cloud/_http.py",第290行,在api_request标头=标头,target_object=_target_object)
file"/home/user/. local/lib/python2.7/site-包/google/Cloud/_http.py",第183行,_make_request返回自己。_do_request(方法,url,头,数据,target_object)File"/home/user/. local/lib/python2.7/site-包/google/Cloud/<--PLHD--4/>http.py,行211,_do_request返回self.http.request(
http-return-self中的文件“/home/user/.local/lib/python2.7/site-packages/google/cloud/_-http.py”,第73行_客户_http
文件"/home/user/. local/lib/python2.7/site-pack/google/Cloud/client.py",第151行,_http。_credentials))
文件“/home/user/.local/lib/python2.7/site packages/google/auth/transport/requests.py”,第161行,在init super(AuthorizedSession,self)中。初始(**kwargs)
文件“/home/user/.local/lib/python2.7/site packages/requests/sessions.py”,第396行,在init self中。挂载('https://',HTTPAdapter())
文件“/home/user/.local/lib/python2.7/site packages/requests\u toolbelt/adapters/appengine.py”,第79行,在init super(AppEngineAdapter,self)中。初始(*args,**kwargs)
文件“/home/user/.local/lib/python2.7/site packages/requests\u toolbelt/adapters/appengine.py”,第60行,在init super(AppEngineMROHack,self)中。初始(*args,**kwargs)
file"/home/user/. local/lib/python2.7/site-包/请求/adapters.py",第127行,在initself.init_poolmanager(pool_connections,pool_maxsize,块=pool_block)
文件“/home/user/.local/lib/python2.7/site packages/requests\u toolbelt/adapters/appengine.py”,第82行,在init\u poolmanager self中。池管理器=\u AppEnginePoolManager(自我验证\u证书)
文件"/home/user/. local/lib/python2.7/site-包/requests_toolbelt/适配器/appengine.py",第122行,initvalidate_certificate=validate_certificate)
[CNNVD]/home/user/. local/lib/python2.7/site-pack/urllib3/contrib/appengine.py文件(第103行,init中的URLFetch在此环境中不可用)
有人能帮帮我吗?谢谢你的时间!
我解决问题...
使用此导入时:
from requests_toolbelt.adapters import appengine
appengine.monkeypatch()
所有超文本传输协议请求都试图使用URLFetch,它在GCE中会产生问题。只有我需要删除这两行,所有作品完美。
谢谢你的时间!GDJ