首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上传python-jose到云运行失败

上传python-jose到云运行失败
EN

Stack Overflow用户
提问于 2022-06-07 21:38:50
回答 1查看 168关注 0票数 0

因此,我已经创建了这个水瓶应用,它将作为我的后端一个定制应用程序。

为了处理JWT-令牌的创建,我决定使用加密的JWS (JWE内部的JWS )。为此,我选择使用python-jose包。我以前试过JWCrypto,但是在本地,它对我来说失败了,我无法用它来包装我的头脑。

在本地设置和测试我的应用程序之后,我正在使用的功能运行得很好。但是,在将它们上传到云运行(成功构建)之后,加密就失败了。声明这一信息:

文件"/usr/local/lib/python3.9/site-packages/jose/jwk.py",第78行,在构造提升JWKError(“无法找到密钥的算法:%s”% key_data) jose.exceptions.JWKError:无法找到密钥的算法:对堆栈的秘密溢出

这是处理加密的函数:

代码语言:javascript
复制
def encode_token(payload):
    jws_secret = "xxxxxxx"
    jwe_key = "xxxxxx"

    signed_token = jws.sign(payload, jws_secret, algorithm='HS256')
    encrypted_signed_token = jwe.encrypt(signed_token, jwe_key, algorithm='dir', encryption='A128GCM')
    
    return encrypted_signed_token

我知道我在分享上面的密钥和秘密,但是我的应用程序还没有连接到数据库,也没有做任何有用的事情。所以没关系:)

这是我的文件:

代码语言:javascript
复制
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install --no-cache-dir -r requirements.txt

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

最后,这是我的requirements.txt (通过pipenv自动生成):

代码语言:javascript
复制
#
# These requirements were autogenerated by pipenv
# To regenerate from the project's Pipfile, run:
#
#    pipenv lock --requirements
#

-i https://pypi.org/simple
click==8.1.3; python_version >= '3.7'
ecdsa==0.17.0; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
flask==2.1.2
gunicorn==20.1.0
importlib-metadata==4.11.4; python_version < '3.10'
itsdangerous==2.1.2; python_version >= '3.7'
jinja2==3.1.2; python_version >= '3.7'
markupsafe==2.1.1; python_version >= '3.7'
pyasn1==0.4.8
python-jose==3.3.0
rsa==4.8; python_version >= '3.6' and python_version < '4'
setuptools==62.3.3; python_version >= '3.7'
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
werkzeug==2.1.2; python_version >= '3.7'
zipp==3.8.0; python_version >= '3.7'

我只是不明白这怎么能在我的机器上工作,但不能在GCP上工作。在我的本地机器(Pipenv )上,JWE完美地返回。我的本地python版本为3.8.3,但我也尝试在Dockerfile中使用3.8和3.10,在部署时也有同样的不幸结果。

有人知道为什么会发生这样的事吗?如果您能向我指出另一种解决方案(如果上面不是固定的),我将永远是伟大的:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-10 21:00:56

问题解决了!

将本地开发环境升级到Python3.10,删除Python,而安装。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72537818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档