function create_remarkable_session
Creates and returns an authenticated requests.Session object configured for interacting with the reMarkable Cloud API.
/tf/active/vicechatdev/e-ink-llm/mixed_cloud_processor.py
664 - 685
simple
Purpose
This function establishes an authenticated session with the reMarkable Cloud service by obtaining a user token through the RemarkableAuth class and configuring a requests.Session with appropriate authorization headers and user agent. It's designed for 'mixed mode' operations that require authenticated access to reMarkable's cloud services for document synchronization or management.
Source Code
def create_remarkable_session(remarkable_config: Dict = None):
"""Create authenticated reMarkable session for mixed mode"""
try:
from cloudtest.auth import RemarkableAuth
auth = RemarkableAuth()
user_token = auth.authenticate()
if not user_token:
raise Exception("Failed to authenticate with reMarkable Cloud")
# Create authenticated session
session = requests.Session()
session.headers.update({
'Authorization': f'Bearer {user_token}',
'User-Agent': 'reMarkable-desktop-win/3.11.1.1951'
})
return session
except ImportError:
raise ImportError("reMarkable authentication not available. Check cloudtest/auth.py")
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
remarkable_config |
Dict | None | positional_or_keyword |
Parameter Details
remarkable_config: Optional dictionary containing configuration parameters for reMarkable authentication. Currently not used in the function implementation but provided for future extensibility. Defaults to None.
Return Value
Returns a requests.Session object configured with authentication headers including a Bearer token and User-Agent string. The session can be used to make authenticated HTTP requests to reMarkable Cloud API endpoints. Returns None implicitly if authentication fails and raises an exception instead.
Dependencies
requestscloudtest.auth (custom module containing RemarkableAuth class)
Required Imports
import requests
from typing import Dict
Conditional/Optional Imports
These imports are only needed under specific conditions:
from cloudtest.auth import RemarkableAuth
Condition: Required for function execution; imported inside try block to handle missing module gracefully
Required (conditional)Usage Example
# Basic usage
try:
session = create_remarkable_session()
# Use the authenticated session to make API calls
response = session.get('https://api.remarkable.com/some-endpoint')
print(response.status_code)
except ImportError as e:
print(f"Authentication module not available: {e}")
except Exception as e:
print(f"Authentication failed: {e}")
# With configuration (for future use)
config = {'timeout': 30, 'retry_count': 3}
session = create_remarkable_session(remarkable_config=config)
Best Practices
- Always wrap calls to this function in try-except blocks to handle ImportError and authentication failures
- The returned session object should be reused for multiple API calls to avoid repeated authentication
- Ensure the cloudtest.auth module and RemarkableAuth class are properly implemented before using this function
- The remarkable_config parameter is currently unused but reserved for future configuration options
- The User-Agent string mimics the official reMarkable desktop client for compatibility
- Consider implementing session timeout and token refresh mechanisms for long-running applications
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class RemarkableAuth 80.8% similar
-
function get_authenticated_session 78.8% similar
-
function test_remarkable_auth 74.3% similar
-
function authenticate_remarkable 73.6% similar
-
function test_remarkable_authentication 68.6% similar