Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user_agent field as a <user_agent> object instead of a string? #51

Open
miaoluda opened this issue Jun 10, 2019 · 0 comments
Open

user_agent field as a <user_agent> object instead of a string? #51

miaoluda opened this issue Jun 10, 2019 · 0 comments

Comments

@miaoluda
Copy link

Python 3.5.2
flask 0.12.2

I am trying to save the log in a file as OutputWriter(output=open('page_view.log','a'), transform=lambda s: str(s)). In the output file I find that user_agent shows as 'user_agent': <UserAgent 'chrome'/74.0.3729.169>
It should be fine for storage backends, but it's a little bit problematic for an output file. (i.e json.dumps get TypeError: <UserAgent 'chrome'/74.0.3729.169> is not JSON serializable)

For the user_agent field:

'user_agent': ctx.request.user_agent,

Is it better like this?

     'user_agent': ctx.request.user_agent.string,

or

     'user_agent': {
        'browser':ctx.request.user_agent.browser,    
        'language':ctx.request.user_agent.language,
        'platform':ctx.request.user_agent.platform,
        'version':ctx.request.user_agent.version,
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant