Comments (5)
It sounds like you've written a custom serializer and it's not returning bytes.
from webob.
@mmerickel thanks for the rapid call out, here is another snippet:
from pyramid.config import Configurator
# Cookie only session, not encrypted but signed to prevent tampering.
from pyramid.session import SignedCookieSessionFactory
from miscutils import get_children_settings
def session_serializer(serializer_name):
if serializer_name == "json":
import json
return json
import pickle
return pickle
def main(global_config, **settings):
"""This function returns a Pyramid WSGI application."""
# setup session factory to use unencrypted but signed cookies
session_settings = get_children_settings(settings, "session")
session_settings["serializer"] = session_serializer(
session_settings.get("serializer")
)
session_factory = SignedCookieSessionFactory(**session_settings)
with Configurator(settings=settings, session_factory=session_factory) as config:
# all of the models for persisting data into our database.
config.include(".models")
# all of the web application routes.
config.include(".routes")
# all of the data we attach to each inbound request.
config.include(".request_methods")
# enable jinja2 templating engine.
config.include(".config_jinja2")
# scan each of these includes for additional configuration.
config.scan()
return config.make_wsgi_app()
from webob.
json.dumps()
returns a unicode string, you'll need to json.dumps().encode('utf8')
to conform to the serializer contract.
from webob.
Thanks, I figured as much. Here is a first pass at making json
compatible with the serializer contract. Let me know if there is a better way.
First I created a new file / module which I may import and pass to the session configurator:
import json
loads = json.loads
def dumps(obj, *args, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw):
result = json.dumps(obj, *args, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw)
return result.encode("utf-8")
and then in my main
function above, I changed the session_serializer
function to look like so:
def session_serializer(serializer_name):
if serializer_name == "json":
import make_post_sell.lib.json_session_serializer as json_serializer
return json_serializer
import pickle
return pickle
This appears to work so I will close this issue. Please feel free to comment after closing if my approach is bad.
from webob.
Actually looks like we already have a batteries included solution, see: https://docs.pylonsproject.org/projects/pyramid/en/latest/api/session.html#pyramid.session.JSONSerializer
def session_serializer(serializer_name):
if serializer_name == "json":
from pyramid.session import JSONSerializer
return JSONSerializer()
from pyramid.session import PickleSerializer
return PickleSerializer()
from webob.
Related Issues (20)
- schedule for next release? HOT 6
- Open file leak with file uploads with wsgi server in daemon mode HOT 6
- request.json_body generates unclosed file ResourceWarning HOT 1
- should `expires` be removed from set_cookie?
- Setting response.expires via timedelta produces an incorrect header value
- 1.8.7: pytest warnings HOT 2
- Mapping urllib.error.HTTPError to webob HTTPError HOT 2
- 1.8.7 fails several tests with python3.9/3.10 with no attribute 'isAlive' HOT 1
- DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13 HOT 6
- Pull Request #438. Request.decode() errors argument ignored
- Misleading documentation of AcceptLanguageValidHeader.lookup HOT 1
- Documentation only shows calling from repl HOT 2
- test_fieldstorage_not_multipart fails
- Adding PATCH method to environ_add_POST
- webob.request.disconnectionerror: the client disconnected while sending the body (22 more bytes were expected) HOT 2
- Is the maintenance plan updated for webob?
- Proposal: Clean up `MultiDict` inheritance from ABCs
- update or remove `__all__` declarations
- Encoding issue in request.py HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webob.