Pickle.load()给出无效的加载密钥,' \ x9c'错误

发布于 2025-02-10 10:05:29 字数 1441 浏览 5 评论 0原文

我正在尝试pickle.load()一个缓存二进制文件,但它一直在给出无效的密钥错误。

我的代码

import pickle
filename = r'C:\Users\user\Downloads\Project\cache\sample'
file = open(filename, "rb")
pickle_time = pickle.load(file)
print(pickle_time)

错误

get key 'filename.df' -> invalid load key, '\x9c'.

我尝试了腌制。加载其他一些在其他人的计算机上写的二进制文件,它效果很好,只有当我ccriple.load()时,它才会丢弃此问题。二进制文件在我的系统上写入。

我使用烧瓶调查来写

from flask_caching import Cache

# app is a dash app
cache = Cache(
        config={
            'CACHE_TYPE': 'FileSystemCache',
            'CACHE_DIR': os.path.join(os.getenv('DASH_CACHE'), 'cache', 'my_data'),
            'CACHE_THRESHOLD': 0,
            'CACHE_DEFAULT_TIMEOUT': 24 * 60 * 60
        }
    )
    

cache.init_app(app.server)

u_id='0000'
ps='system0000'
session_id = u_id + '___' + ps + '___' +datetime.now().strftime('%Y%m%d_%H%M%S')

# RH is an internal class for reading data from DB and performing post processing
df = RH.GeneratePriceJSON(lat, lng, 15,currency=currency, no_limit=False)
df = json.dumps(df)

@app.callback(
[Output('some-value', 'children')],
[Input('some-url', 'search')],
)
def foo(some_url):
    with app.server.app_context():
        cache.set(session_id + '.' + 'df', df)
        df = session_id + '.' + 'df'
    return df

I am trying to pickle.load() a cache binary file but it keeps on giving invalid key errors.

My code

import pickle
filename = r'C:\Users\user\Downloads\Project\cache\sample'
file = open(filename, "rb")
pickle_time = pickle.load(file)
print(pickle_time)

The error

get key 'filename.df' -> invalid load key, '\x9c'.

I tried pickle.load on some other binary files written on someone else's computer and it worked fine, it's only throwing this issue when I pickle.load() binary files writen on my system.

I write using flask-cache

from flask_caching import Cache

# app is a dash app
cache = Cache(
        config={
            'CACHE_TYPE': 'FileSystemCache',
            'CACHE_DIR': os.path.join(os.getenv('DASH_CACHE'), 'cache', 'my_data'),
            'CACHE_THRESHOLD': 0,
            'CACHE_DEFAULT_TIMEOUT': 24 * 60 * 60
        }
    )
    

cache.init_app(app.server)

u_id='0000'
ps='system0000'
session_id = u_id + '___' + ps + '___' +datetime.now().strftime('%Y%m%d_%H%M%S')

# RH is an internal class for reading data from DB and performing post processing
df = RH.GeneratePriceJSON(lat, lng, 15,currency=currency, no_limit=False)
df = json.dumps(df)

@app.callback(
[Output('some-value', 'children')],
[Input('some-url', 'search')],
)
def foo(some_url):
    with app.server.app_context():
        cache.set(session_id + '.' + 'df', df)
        df = session_id + '.' + 'df'
    return df

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尾戒 2025-02-17 10:05:29

解决了无效的负载密钥问题:它是烧瓶 - 碰到版本,1.11.1引发错误,通过降级至1.10.1

pip install Flask-Caching==1.10.1

原始答案

Resolved the invalid load key issue: it was the Flask-Caching version, 1.11.1 throws the error, resolved by downgrading to 1.10.1

pip install Flask-Caching==1.10.1

Original Answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文