ylq5126 commented on issue #29619:
URL: https://github.com/apache/superset/issues/29619#issuecomment-2246817696

   > The error "TypeError: cannot use a string pattern on a bytes-like object" 
indicates a mismatch between string and byte data types. To resolve this issue 
in your Superset application when using Redis for session management, ensure 
that the session data is properly encoded and decoded.
   > 
   > Here's how you can adjust your `superset_config.py` to handle this:
   > 
   > 1. **Ensure Proper Encoding and Decoding**:
   >    Make sure that any data being stored or retrieved from the session is 
properly encoded to bytes or decoded to strings as needed.
   >    ```python
   >    from redis import Redis
   >    
   >    SESSION_TYPE = "redis"
   >    SESSION_REDIS = Redis(host="superset-redis-prod-01", port=6379, db=0)
   >    SESSION_USE_SIGNER = True
   >    SESSION_COOKIE_SECURE = True
   >    SESSION_COOKIE_HTTPONLY = True
   >    SESSION_COOKIE_SAMESITE = "Lax"
   >    
   >    # Example of encoding and decoding session data
   >    def encode_data(data):
   >        return data.encode('utf-8') if isinstance(data, str) else data
   >    
   >    def decode_data(data):
   >        return data.decode('utf-8') if isinstance(data, bytes) else data
   >    ```
   > 2. **Check Session Data Handling**:
   >    If you are manually handling session data, ensure that you encode 
strings to bytes before storing them in Redis and decode bytes to strings when 
retrieving them.
   >    ```python
   >    # Example usage
   >    session_data = "some string data"
   >    encoded_session_data = encode_data(session_data)
   >    # Store `encoded_session_data` in Redis
   >    
   >    # When retrieving
   >    retrieved_data = decode_data(encoded_session_data)
   >    ```
   > 
   > By ensuring that the data types are correctly handled, you can avoid the 
"TypeError: cannot use a string pattern on a bytes-like object" error 
[[1]](https://github.com/apache/superset/blob/master/docs/docs/security/security.mdx).
   > 
   > _To continue talking to [Dosu](https://dosu.dev), mention @dosu._
   
   in docker 4.0.2-dev, werkzeug version not support bytes value


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to