Pickle.load()给出无效的加载密钥,' \ x9c'错误
我正在尝试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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了无效的负载密钥问题:它是烧瓶 - 碰到版本,1.11.1引发错误,通过降级至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
Original Answer