Skip to content

HTTPException pickle fails when constructed using named parameter status_code #1669

Answered by Kludex
nexusdk asked this question in Q&A
Discussion options

You must be logged in to vote

This works if you use the copyreg module.

import copyreg
import pickle
from starlette.exceptions import HTTPException

def pickle_http_exception(exc):
    return HTTPException, (exc.status_code, exc.detail, exc.headers)

copyreg.pickle(HTTPException, pickle_http_exception)
print(pickle.loads(pickle.dumps(HTTPException(status_code=404))))

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@nexusdk
Comment options

Comment options

Kludex
Jun 9, 2022
Maintainer Sponsor

You must be logged in to vote
0 replies
Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1663 on June 02, 2022 06:27.